php tutorial - PHP Read More Link - php programming - learn php - php code - php script




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)
)
click below button to copy the code. php tutorial - team

Set Connection Variables in “config.php” File:


<?php
// Set Connection Variable //
$SERVER_NAME='localhost';
$SERVER_USERNAME='root';
$SERVER_PASSWORD='';
$DATABASE_NAME='store';

?>
click below button to copy the code. php tutorial - team

To Set Limit Variable To Display Only 2 Records:


$get_limit= $_GET['get_limit'];
$limit=$get_limit+2;
click below button to copy the code. php tutorial - team

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


<?php

class Connection{

//connection start
public function __construct(){
require('config.php');
$this->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();
?>
click below button to copy the code. php tutorial - team

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

 read-more

Learn php - php tutorial - read-more - php examples - php programs

PHP File: index.php

Given below code creates an HTML page with 2 records initially as $limit value is 2 and read more link. My connection is set in “config.php” file and query is placed in “connection.php” .

<?php
// To Hide Notice Error //
error_reporting(~E_NOTICE);

// Include Connection File //
include('connection.php');
?>
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="main">
<div id="login">
<table>
<tr>
<th><h2>Click To Read More..</h2><hr/><th>
</tr>
<?php
// Set $limit Variable To Display Only 2 Records //
$get_limit = $_GET['get_limit'];
$limit = $get_limit + 2;

//Select Query Call //
$a = $obj->select_query($limit) or die($a . "<br/><br/>" . mysqli_error());
// Display Records //
while ($row = mysqli_fetch_array($a)) {
?>
<tr>
<td><?php echo $row['comments']; ?></td>
</tr>
<?php
}
?>
</table>
<br/>
<a href="/read-more-php/index.php?get_limit=<?php echo $limit; ?> ">Read More..</a>
</div>
</div>
</body>
</html>
click below button to copy the code. php tutorial - team

CSS File: style.css

Styling HTML elements.

@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{
background-color: #FFBC00;
}
click below button to copy the code. php tutorial - team


Related Searches to PHP Read More Link

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

×