Read more with php

This tutorial enables you to display two records when user clicks on read more link using object-oriented funtionality.

In my example, I have made a folder named read-more-php and placed these pages index.php, config.php, connection.php and style.css.

Further set $get_limit variable to travel in the url through the read more link which increments by 2 each time when user clicks on the link and store its value in $limit variable which is passed to sql query to limits the records while displaying it on page.

My SQL Code Segment:

To create database and table, execute following codes in your MySQL .

 CREATE DATABASE store; CREATE TABLE link( id int(10) NOT NULL AUTO_INCREMENT, comments varchar(255) NOT NULL, PRIMARY KEY (id) ) 

Set Connection Variables in “ config.php ” File:

To Set Limit Variable To Display Only 2 Records:

 $get_limit= $_GET['get_limit']; $limit=$get_limit+2; 

Class “ connection.php ” Having Connection String And Query:

 conn=new mysqli($SERVER_NAME,$SERVER_USERNAME,$SERVER_PASSWORD,$DATABASE_NAME); > // Query To Fetch Records From Link Table On The Basis Of $limit Value // public function select_query($limit)< $sql = mysqli_query($this->conn,"SELECT * FROM link LIMIT ".$limit); return $sql; > //connection close public function __destruct()< mysqli_close($this->conn); > > $obj= new Connection(); ?> 

Watch out live demo or download the given codes to use it.

PHP File: index.php

Given below code creates an HTML page with 2 records initially as $limit value is 2 and read more link.

Читайте также:  Android java native method

My connection is set in “ config.php ” file and query is placed in “ connection.php ” .

       

Click To Read More..


select_query($limit) or die($a . "

" . mysqli_error()); // Display Records // while ($row = mysqli_fetch_array($a)) < ?> ?>

">Read More..

CSS File: style.css

 @import http://fonts.googleapis.com/css?family=Raleway; /*---------------------------------------------- CSS Settings For HTML Div ExactCenter ------------------------------------------------*/ body < background-color:#D8C092; margin:100px,50px; padding:100px,50px>#main < width:960px; margin:100px auto; margin-left:600px; font-family:raleway; background-color:#FEFFED >h2 < background-color:#FEFFED; text-align:center; border-radius:10px 10px 0 0; margin:-10px -40px; padding:15px >hr < border:0; border-bottom:1px solid #ccc; margin:10px -47px; margin-bottom:30px >#login < width:259px; float:left; border-radius:10px; font-family:raleway; border:2px solid #ccc; padding:10px 40px 25px; margin-top:70px; background-color:#FEFFED >a < text-decoration:none; color:#6495ed >#read

Conclusion:

It becomes easy to use read more functionality in page using PHP by avoiding complex coding with javascript and ajax. Hope you liked it, keep reading our blogs.

Источник

I am working on a dashboard similar to WordPress today, therefore there are many stories and each story has an excessive amount of details. I’ll learn here how to add ‘Read more’ link on each story.

I’m having trouble figuring out how to keep the dashboard page’s descriptions short. A show more link will appear to the user on many websites where the further words are hidden if the description text is longer than a few characters.

So I need to create “Read More…” link and if the user is interested then he can click on more link and see the full content.

You can also check other tutorials of dynamic read more Using jQuery

Here is a simple tutorial to achieve “Read More..” link functionality.

To create a link dynamically, I need first to create a connection with the database.

Created Database Connection With MySQLi

Created connect.php file into php application, We will pass MySQL server hostname, username, dbname and password into mysqli_connect() method.

$con = mysqli_connect(«localhost»,»my_user»,»my_password»,»my_db»); // Check connection if (mysqli_connect_errno())

Get All Records With MySqli

We will get all records with description data from the database.

Now I am creating a readMoreFunction(. ) general function to display link on the dashboard.

Above functionally has been created using of core php ,you can also create this functionality with jquery and PHP

I hope this will help you!

Источник

How to Create Read More in PHP?

If you’re developing website with PHP to list multiple articles on home page. Then definitely you will need to display only few starting lines of each article content with “Read More…” link to display full article content in a page when click on “Read More…” link. It would be best approach to display “Read More” with each article because it will allow you to display more articles in a single page that will increase readability of page.

So here in this post, you will learn how to create “Read More…” link and clicking on it will display full content in a page.

Here is an example of creating read more link of content to display few line of content with “Read More…” and by clicking “Read More…” will display full content in page.

The below code will display content with few lines with “Read More…” link.

This is a readMore() function to create read more link of a content.

  • Star Rating System with Ajax, PHP and MySQL
  • Create Event Calendar with jQuery, PHP and MySQL
  • Build Your Own CAPTCHA Script with PHP
  • Convert Unix Timestamp To Readable Date Time in PHP
  • Inventory Management System with Ajax, PHP & MySQL
  • Create Live Editable Table with jQuery, PHP and MySQL
  • Live Add Edit Delete datatables Records with Ajax, PHP and MySQL
  • Stripe Payment Gateway Integration in PHP
  • Export Data to Excel with PHP and MySQL
  • Star Rating System with Ajax, PHP and MySQL
  • Create Dynamic Bootstrap Tabs with PHP & MySQL
  • How To Create Simple REST API in PHP

Here we have developed a complete read more script the help of above example code. You can see this script in action from below live demo link.

Источник

PHP — Dynamic Comment With «Read more» Feature

In this tutorial we will create Dynamic Comment With «Read more» Feature using PHP. PHP is a server-side scripting language designed primarily for web development. Using PHP, you can let your user directly interact with the script and easily to learned its syntax. It is mostly used by a newly coders for its user friendly environment. So let’s now do the coding.

Before we get started:

First you have to download & install XAMPP or any local server that run PHP scripts. Here’s the link for XAMPP server https://www.apachefriends.org/index.html. And this is the link for the jquery that i used in this tutorial https://jquery.com/. Lastly, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.

Creating Database

tut1

Open your database web server then create a database name in it db_comment, after that click Import then locate the database file inside the folder of the application then click ok.

Creating the database connection

Open your any kind of text editor(notepad++, etc..). Then just copy/paste the code below then name it conn.php.

Creating The Interface

This is where we will create a simple form for our application. To create the forms simply copy and write it into your text editor, then save it as index.php.

Creating PHP Query

This code contains the php query of the application. This code will sent the data inputs to the database server by sending ajax request method, and display the data back to the webpage. To do that just copy and write this block of codes inside the text editor, then save it as shown below. save_comment.php

Creating jQuery Script

This is where the code that uses ajax request been used. This code is consist of different functionalities it includes the sending data to the database, and extending the comment by clicking. To do this just copy and write these block of codes inside the text editor, then save it as script.js inside the js folder.

There you have it we successfully created Dynamic Comment With «Read more» Feature using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding.

Источник

Оцените статью