PHP Paging Not Updating Results - php

I am creating a page that lists celebrities on Twitter. The page displays 10 different results as it should for the first loop but it doesn't seem to update the $result to pull the next 10 values from the database (for the next set of pages etc).
<?php
// connect to the database
$con = mysql_connect("localhost","someuid","somepwd");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("celebrity_twitter", $con);
$result = mysql_query("SELECT * FROM celebrities");
// number of results to show per page
$per_page = 10;
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $per_page);
// check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1)
if (isset($_GET['page']) && is_numeric($_GET['page']))
{
$show_page = $_GET['page'];
// make sure the $show_page value is valid
if ($show_page > 0 && $show_page <= $total_pages)
{
$start = ($show_page -1) * $per_page;
$end = $start + $per_page;
}
else
{
// error - show first set of results
$start = 0;
$end = $per_page;
}
}
else
{
// if page isn't set, show first set of results
$start = 0;
$end = $per_page;
}
// display data in table
echo "<table class='table table-striped'>";
echo "<tr> <th>Avatar</th> <th>Celebrity Name</th> </tr>";
// loop through results of database query, displaying them in the table
for($i = $start; $i < $end; $i++ && $row = mysql_fetch_array($result) )
{
// make sure that PHP doesn't try to show results that don't exist
if ($i == $total_results) { break; }
// echo out the contents of each row into a table
echo "<tr>";
echo "<td><img height='73' width='73' src=" . "http://api.twitter.com/1/users/profile_image?screen_name=" . $row['avatar'] . "&size=bigger></td>";
echo "<td><a href=" . $row['url'] . " target='_blank'>" . $row['uid'] . "</td></a>";
echo "</tr>";
}
// close table>
echo "</table>";
// display pagination
echo "<strong>Page: </strong>";
for ($i = 1; $i <= $total_pages; $i++)
{
echo "<a href='index.php?page=$i'>$i</a> ";
}
?>

I'm using this at the moment and it's working perfectly fine for me, I hope it works for you too : PHP Pagination

You are not positioning yourself in the database, you always read the first elements:
// loop through results of database query, displaying them in the table
for($i = $start; $i < $end; $i++ && $row = mysql_fetch_array($result) )
{
// make sure that PHP doesn't try to show results that don't exist
if ($i == $total_results) { break; }
The proper way of doing this would be using the LIMIT clause of MySQL, with a special clause for recovering the true number of records
SELECT SQL_CALC_FOUND_ROWS * FROM celebrities LIMIT $start, $resultsperpage;
SELECT FOUND_ROWS(); // This is number of celebrities
This means that you need to calculate $start "before" running the query, i.e., "before" you know whether $start is a valid start at all. So you have to prepare for the case in which no rows are returned.
A quick alternative, which is pretty wasteful, is to retrieve everything and display only wanted rows:
// loop through results of database query, displaying them in the table
for ($i = 0; $i < $total_results; $i++)
{
$row = mysql_fetch_array($result);
if ($i < $start) continue;
if ($i == $end) break;
LIMIT implementation
mysql_select_db("celebrity_twitter", $con);
// number of results to show per page
$per_page = 10;
// We REALLY ought to move on to PDO: mysql_* will be deprecated sooner or later
$query = mysql_query('SELECT SQL_CALC_FOUND_ROWS * FROM celebrities');
// check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1)
if (isset($_GET['page']) && is_numeric($_GET['page']))
{
$show_page = (int)$_GET['page'];
// make sure the $show_page value is valid
if ($show_page > 0)
$start = ($show_page -1) * $per_page;
else
$start = 0;
$query .= " LIMIT $start, $per_page;";
$paged = True;
}
else
{
$paged = False;
// The query having no LIMIT, it will retrieve everything
// if (!$paged), later we will display a link "Show Paged".
}
// Now run the query
$result = mysql_query($query);
// Also fetch REAL number of rows in table {{{
$exec = mysql_query("SELECT FOUND_ROWS() AS results;");
$tuple = mysql_fetch_assoc($exec);
$results= $tuple['results'];
mysql_free_result($exec);
unset($exec, $tuple);
// }}}
// If paging, calculate page number. Later, if ($paged), we'll display the pager.
if ($paged)
{
$maxpages = ceil($results / $per_page);
if ($page > $maxpages)
$page = $maxpages+1; // We fetch nothing.
else
$page = floor($start / $per_page)+1;
}
// display data in table. It is best to calculate $html first
// and then output it all together at end if no error.
$html = "<table class='table table-striped'>";
$html .= "<tr> <th>Avatar</th> <th>Celebrity Name</th> </tr>";
// loop through results of database query, displaying them in the table
// Here, we get all and only good results, so we need not check anything
while($row = mysql_fetch_array($result))
{
// echo out the contents of each row into a table
$html .= "<tr>";
}

Related

how to pagify genre search result on the movie database

I have a website that I'm building on my localhost using the MVC design pattern. I have button on click that will display all the genres in TheMovieDatabase which I got using the TheMovieDatabaseAPI. On click of a genre I get data for Page 1 with 20 results. But, I couldn't figure out how to request the results for page 2. These requests are made using PHP.
I am assuming you are taking about pagination using, I am also assuming you are using mySQL as database, I am not sure which framework you are using,
Here is a function i use, you can build around this
function get_movie($page = 1){
global $database_connection;
$start = 0; //Don't modify this
$limit = 10; //set this to 20 to display 20 movies per page
$start = ($page - 1)* $limit;
//get the movie from the table
$sql = "SELECT genre FROM movie_table LIMIT $start, $limit";
$result = mysqli_query($database_connection, $sql);
while ($row = mysqli_fetch_array($result)){
echo "<div>$row['genre']</div>";
}
$movie_rows = mysqli_num_rows (mysqli_query($database_connection ,"SELECT * FROM movie_table"));
$total = ceil($testimony_rows / $limit);
if (isset($page)){
echo "<div>";
echo "<ul class='pager'>";
if($page > 1) {
echo "<a href='?page=".($page - 1)."' style='float: left;' class=' w3-sand w3-btn w3-margin w3-round'>Previous</a>";
}
for($i = 1; $i <= $total; $i++) {
if($i == $page) { echo "<li class='active current'>".$i."</li>"; }
else { echo "<li><a href='?page=".$i."'>".$i."</a></li>"; }
}
if($page != $total) {
echo "<a href='?page=".($page + 1)."' class='w3-btn w3-margin w3-sand w3-round'>Next</a>";
}
echo "</ul></div>";
}
}
you can use limit and offset to get the result for page 2.
Example :- if you are using query builder to get the results
$limit = 20;
$offset = 21;
$queryBuilder->select('d')
->from(<table name>, 'd')
->setMaxResults($limit)
->setFirstResult($offset)
->setParameter('limit', $limit)
->setParameter('offset', $offset);
If you are using raw query :
SELECT * FROM table LIMIT 20 OFFSET 21
Else you can use paginator too
$paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($query);
$totalItems = count($paginator);
$pagesCount = ceil($totalItems / $pageSize);
// now get one page's items:
$paginator
->getQuery()
->setFirstResult($pageSize * ($currentPage-1)) // set the offset
->setMaxResults($pageSize); // set the limit
foreach ($paginator as $pageItem) {
echo "<li>" . $pageItem->getName() . "</li>";
}

show page numbering in PHP

I am using this coed in PHP to show next and previous buttons for records in a mysql database:
$sql="SELECT * from customer";
$rs=mysql_query($sql,$conn) or die(mysql_error());
$MaxRowsPerPage = 25;
$total_records = mysql_num_rows($rs);
$total_pages = ceil($total_records / $MaxRowsPerPage);
if(isset($_GET["page"])) {
$page = $_GET["page"];
} else {
$page=1;
}
$start_from = ($page-1) * $MaxRowsPerPage;
$sql.=" LIMIT $start_from, $MaxRowsPerPage";
I am echoing $total_records to show the total amount, how can i show the number from and to on the current page. for example, on page 1 it will be showing records 1 to 25 (because max rows per page is 25) and then page 2 will be showing records 26 to 50 and so on...
There a are many ways of doing this, but here's a simple pagination example I made. It will also show 1-25, 26-50 etc. It's heavily commented so it should be easy to understand.
<?php
// Connect to database
include 'includes/db_connect.php';
// Find total number of rows in table
$result = mysql_query("SELECT COUNT(*) FROM example_table");
$row = mysql_fetch_array($result);
$total_rows = $row[0];
// Set rows per page
$rows_per_page = 25;
// Calculate total number of pages
$total_pages = ceil($total_rows / $rows_per_page);
// Get current page
$current_page = (isset($_GET['p']) && $_GET['p'] > 0) ? (int) $_GET['p'] : 1;
// If current page is greater than last page, set it to last.
if ($current_page > $total_pages)
$current_page = $total_pages;
// Set starting post
$offset = ($current_page - 1) * $rows_per_page;
// Get rows from database
$result = mysql_query("SELECT * FROM example_table LIMIT $offset, $rows_per_page");
// Print rows
echo '<hr>';
while($row = mysql_fetch_array($result))
{
echo $row['id'].'<br />';
echo $row['text'];
echo '<hr>';
}
// Build navigation
// Range of pages on each side of current page in navigation
$range = 4;
// Create navigation link for previous and first page.
if ($current_page > 1)
{
$back = $current_page - 1;
echo ' PREV ';
if ($current_page > ($range + 1))
echo ' 1... ';
}
else
echo ' PREV ';
// Create page links, based on chosen range.
for ($i = $current_page - $range; $i < ($current_page + $range) + 1; $i++)
{
if ($i > 0 && $i <= $total_pages)
if ($i == $current_page)
echo ' [<strong>'.$i.'</strong>] ';
else
echo ' '.$i.' ';
}
// Create navigation link for next and last page.
if ($current_page != $total_pages)
{
$next = $current_page + 1;
if (($current_page + $range) < $total_pages)
echo ' ...'.$total_pages.' ';
echo ' NEXT ';
}
else
echo ' NEXT ';
?>

PHP Pagination of MySQL Query not incrementing/decrementing properly

I'm having trouble with the follow PHP which paginates the results of a MySQL query.
When I go to webpagename.php with the first page of the results and click Previous, the browser changes to webpagename.php?page=-1 and shows the first page of results again. If I click Previous again, it changes to webpagename.php?page=-2 and shows Page 1 of the results again, etc.
When I go to webpagename.php with the first page of the results and click Next, the browser changes to webpagename.php?page=1 and shows the first page of results again. I then have to hit Next a second time to move to Page 2.
When I go to the last page of the results - Page 8 - and click Next, the browser changes to webpagename.php?page=9 and shows Page 1 of the results. If I click Next again, it shows webpagename.php?page=10 and shows Page 1 of the results again, etc.
Expected Results:
When on Page 1 and a user hits Previous, I would like the code to do nothing/not decrement. When on Page 8 - the last page of results, I would like the code to do nothing/not increment. Of course, I would also expect that if you hit Next from Page 1 that it doesn't display Page 1 a second time but rather goes to Page 2.
Your exact changes to this code to make it work properly are very much appreciated. Thank you for time.
<?php
mysql_connect("localhost","username","password") or die(mysql_error());
mysql_select_db("dbname") or die(mysql_error());
// number of results to show per page
$per_page = 10;
// figure out the total pages in the database
$result = mysql_query("SELECT * FROM uc_users LEFT JOIN ent_dancers ON uc_users.id = ent_dancers.id WHERE ent_dancers.DancerYesNo = '1' AND ent_dancers.DancerEnabledYesNo = '1' ORDER BY uc_users.display_name ASC");
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $per_page);
// check if the 'page' variable is set in the URL (ex: webpagename.php?page=1)
if (isset($_GET['page']) && is_numeric($_GET['page']))
{
$show_page = $_GET['page'];
// make sure the $show_page value is valid
if ($show_page > 0 && $show_page <= $total_pages)
{
$start = ($show_page -1) * $per_page;
$end = $start + $per_page;
}
else
{
// error - show first set of results
$start = 0;
$end = $per_page;
}
}
else
{
// if page isn't set, show first set of results
$start = 0;
$end = $per_page;
}
// display pagination
// display data in table
echo "<div class='dancerbio'>";
echo "<div class='uts-1'>";
// loop through results of database query, displaying them in the table
for ($i = $start; $i < $end; $i++)
{
// make sure that PHP doesn't try to show results that don't exist
if ($i == $total_results) { break; }
// echo out the contents of each row into a table
$rowid = mysql_result($result, $i, 'id');
echo "<div class='uts-1-1'><a class='bodytxt5' href='webpagename-details.php?userid=$rowid'>" . mysql_result($result, $i, 'display_name') . "</a></div>";
}
// close table>
echo "<div class='ugen-1'></div>";
echo "</div>";
$prev = $_GET['page'] - 1;
echo "<div style='clear:both;height:1px;overflow: hidden;'></div>";
echo "<br /><a class='bodytxt5' href='webpagename.php?page=" . $prev . "'>Prev</a> ";
for ($i = 1; $i <= $total_pages; $i++)
{
echo "<a class='bodytxt5' href='webpagename.php?page=$i'>$i</a> ";
}
$next = $_GET['page'] + 1;
echo " <a class='bodytxt5' href='webpagename.php?page=" . $next . "'>Next</a> ";
echo "</div>";
// pagination
?>
replace this:
if (isset($_GET['page']) && is_numeric($_GET['page']))
{
$show_page = $_GET['page'];
// make sure the $show_page value is valid
if ($show_page > 0 && $show_page <= $total_pages)
{
$start = ($show_page -1) * $per_page;
$end = $start + $per_page;
}
else
{
// error - show first set of results
$start = 0;
$end = $per_page;
}
}
else
{
// if page isn't set, show first set of results
$start = 0;
$end = $per_page;
}
by this:
if (isset($_GET['page']) && is_numeric($_GET['page']))
{
$show_page = $_GET['page'];
if ($show_page > 0 && $show_page <= $total_pages)
{
$start = ($show_page -1) * $per_page;
$end = $start + $per_page;
}
elseif ($show_page > $total_pages)
{
$show_page=$total_pages;
$start = ($show_page -1) * $per_page;
$end = $start + $per_page;
}
else {
$show_page=1;
$start = 0;
$end = $per_page;
}
}
else {
$show_page=1;
$start = 0;
$end = $per_page;
}
then :
$prev=$show_page-1;
$next=$show_page+1;
if($show_page>1){//this way previsous won't appear if you are at page 1 already
//show previous div
}
if($show_page<$total_pages){ //this way next won't appear unless you are not at the last page
//show next div
}
Make a variable $page set it equal to $_GET['page'].
if(isset($_GET['page'])){
$page = $_GET['page'];
}
else{
$page = 1;
}
you need to put a condition before echoing previous link to check whether $_GET['page'] is set or not and is greater than 1.
Like this:
if($page!=($start+1)){
$prev = $page - 1;
echo "<div style='clear:both;height:1px;overflow: hidden;'></div>";
echo "<br /><a class='bodytxt5' href='webpagename.php?page=" . $prev . "'>Prev</a> ";
}
Add another condition for next
if($page!=$total_pages)
{
$next = $page+1
echo " <a class='bodytxt5' href='webpagename.php?page=" . $next . "'>Next</a> ";
echo "</div>";
}
I hope your issue is solved.
if (isset($_GET['page']) && is_numeric($_GET['page']))
{
$show_page = $_GET['page'];
// make sure the $show_page value is valid
if ($show_page > 0 && $show_page <= $total_pages)
{
$start = ($show_page -1) * $per_page;
$end = $start + $per_page;
}
else
{
// error - show first set of results
$start = 0;
$end = $per_page;
$show_page=1
}
}
else
{
// if page isn't set, show first set of results
$start = 0;
$end = $per_page;
$show_page=1;
}
// display pagination
// display data in table
echo "<div class='dancerbio'>";
echo "<div class='uts-1'>";
// loop through results of database query, displaying them in the table
for ($i = $start; $i < $end; $i++)
{
// make sure that PHP doesn't try to show results that don't exist
if ($i == $total_results) { break; }
// echo out the contents of each row into a table
$rowid = mysql_result($result, $i, 'id');
echo "<div class='uts-1-1'><a class='bodytxt5' href='webpagename-details.php?userid=$rowid'>" . mysql_result($result, $i, 'display_name') . "</a></div>";
}
// close table>
echo "<div class='ugen-1'></div>";
echo "</div>";
if($show_page!=($start+1)){
$prev = $page - 1;
echo "<div style='clear:both;height:1px;overflow: hidden;'></div>";
echo "<br /><a class='bodytxt5' href='webpagename.php?page=" . $prev . "'>Prev</a> ";
}
for ($i = 1; $i <= $total_pages; $i++)
{
echo "<a class='bodytxt5' href='webpagename.php?page=$i'>$i</a> ";
}
if($show_page!=$total_pages)
{
$next = $page+1
echo " <a class='bodytxt5' href='webpagename.php?page=" . $next . "'>Next</a> ";
echo "</div>";
}
// pagination
?>

How to create paginated table from MySQL database?

I'm about to start work on a new project and wanted some advice before beginning.
I have a MySQL table that I need to display on my website. The table has over 100 million lines in it. The table has 2 columns in it: domainid and domainname.
The domainid column is simply numbers starting at 1 and going up to over 100 million. In the domainname table I have a list of domains such as this:
test1
test2
test3
test4
test5
test6
Basically what I'm trying to do is this:
I want to display 1000 domains per page on my website - in a table. The table would be 4 columns and 250 lines. To start with, I'm not sure exactly how to get data from the database and actually display it in my HTML table. I know it can be done with PHP of course, just not sure how.
The second thing I need to add is some sort of pagination. It doesn't need to be pretty, I just need a way to have pages auto generated at the bottom of the list so that people can go from one page to the next and view 1000 records on each page - obviously I wouldn't want all 100 million records displayed on a single page.
So here's the problem I'm having: I'm not sure how to get the MySQL data and display it on my website quickly - I don't want it taking forever to load the pages just because the database is large. And second I really need a way to add pagination to the table.
If anyone could point me in the right direction, it would be much appreciated. I'm not sure how difficult doing this is going to be, but any assistance you can provide would be great.
This will give you the total number of rows
Select count(*) from yourtable
Then to display a page, do some whizzy maths like this
$rows_per_page = 1000;
$page_no = 2; // hint, start counting pages at page 0, it will make things easier
$offset = $page_no * $rows_per_page;
// 0 = offset (where to start)
// 1000 = number of rows returned
select * from yourtable limit $offset,$rows_per_page
Because you have so many rows, I would use an html select to choose which page you want to go to, or just have a next and previous button and leave it like that
To figure out how many page there are, you need some more maths
$total_rows = 100000000;
$rows_per_page = 1000;
$num_pages = $total_rows / $rows_per_page;
USE THIS CODE :
Create pages config,paginate,index in php.
Here Paginate page creates design for format(prev and next button to scroll page).
Config create connection with database.
index page firstly define the variable for create number of result per page, page number , total result etc
index page(design) defines the how page show ,which can be modify by you according to you priority to show page design.
CONFIG.PHP
$mysql_hostname = "host";
$mysql_user = "usr";
$mysql_password = "pass";
$mysql_database = "db";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Opps some thing went wrong");
mysql_select_db($mysql_database, $bd) or die("Error on database connection");
PAGINATE.PHP
function paginate($reload, $page, $tpages) {
$adjacents = 2;
$prevlabel = "‹ Prev";
$nextlabel = "Next ›";
$out = "";
// previous
if ($page == 1) {
$out.= "<span>".$prevlabel."</span>\n";
} elseif ($page == 2) {
$out.="<li>".$prevlabel."\n</li>";
} else {
$out.="<li>".$prevlabel."\n</li>";
}
$pmin=($page>$adjacents)?($page - $adjacents):1;
$pmax=($page<($tpages - $adjacents))?($page + $adjacents):$tpages;
for ($i = $pmin; $i <= $pmax; $i++) {
if ($i == $page) {
$out.= "<li class=\"active\"><a href=''>".$i."</a></li>\n";
} elseif ($i == 1) {
$out.= "<li>".$i."\n</li>";
} else {
$out.= "<li>".$i. "\n</li>";
}
}
if ($page<($tpages - $adjacents)) {
$out.= "<a style='font-size:11px' href=\"" . $reload."&page=".$tpages."\">" .$tpages."</a>\n";
}
// next
if ($page < $tpages) {
$out.= "<li>".$nextlabel."\n</li>";
} else {
$out.= "<span style='font-size:11px'>".$nextlabel."</span>\n";
}
$out.= "";
return $out;
}
index.php
<?php
include('config.php'); //include of db config file
include ('paginate.php'); //include of paginat page
$per_page = 1000; // number of results to show per page
$result = mysql_query("SELECT * FROM YOURTABLE");
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $per_page);//total pages we going to have
//-------------if page is setcheck------------------//
if (isset($_GET['page'])) {
$show_page = $_GET['page']; //current page
if ($show_page > 0 && $show_page <= $total_pages) {
$start = ($show_page - 1) * $per_page;
$end = $start + $per_page;
} else {
// error - show first set of results
$start = 0;
$end = $per_page;
}
} else {
// if page isn't set, show first set of results
$start = 0;
$end = $per_page;
}
// display pagination
$page = intval($_GET['page']);
$tpages=$total_pages;
if ($page <= 0)
$page = 1;
?>
// DESIGNING and displaying data(code continuing in index.php)
<?php
$reload = $_SERVER['PHP_SELF'] . "?tpages=" . $tpages;
echo '<div class="pagination"><ul>';
if ($total_pages > 1) {
echo paginate($reload, $show_page, $total_pages);
}
echo "</ul></div>";
// display data in table
echo "<table class='table table-bordered'>";
echo "<thead><tr><th>DOMAIN CODE</th> <th>DOMAIN Name</th></tr></thead>";
// loop through results of database query, displaying them in the table
for ($i = $start; $i < $end; $i++) {
// make sure that PHP doesn't try to show results that don't exist
if ($i == $total_results) {
break;
}
// echo out the contents of each row into a table
echo "<tr " . $cls . ">";
echo '<td>' . mysql_result($result, $i, 'domainid') . '</td>';
echo '<td>' . mysql_result($result, $i, 'domainname') . '</td>';
echo "</tr>";
}
// close table>
echo "</table>";
// pagination
?>

pagination of search result is not working

Pagination problem in search result
I am trying to paginate the search results, Here is the code that i'm using to look up for the search queries from user's form. I am getting search results paginated, but when i click 2 nd page of results it shows undefined index for those item posted...While gone through tutorials i have seen to use $_GET instead of $_POST ,after doing that chane also no improvement in results
As i am new to this php code, can you guys help or guide me in the right direction?
/////////////test.php//////////////////
mysqli_report(MYSQLI_REPORT_ERROR);
// number of results to show per page
$per_page = 2;
// figure out the total pages in the database
if ($result = $mysqli->query("SELECT * FROM bridegroom where Gender like '%$Name%' and Castest like'%$caste%' and Location like '%$location%' order by AGE"))
{
if ($result->num_rows != 0){
$total_results = $result->num_rows;
// ceil() returns the next highest integer value by rounding up value if necessary
$total_pages = ceil($total_results / $per_page);
if (isset($_GET['page']) && is_numeric($_GET['page']))
{
$show_page = $_GET['page'];
if ($show_page > 0 && $show_page <= $total_pages)
{
$start = ($show_page -1) * $per_page;
$end = $start + $per_page;
}
else
{
$start = 0;
$end = $per_page;
}
}
else
{
$start = 0;
$end = $per_page;
}
// display pagination
echo "<p> <b>View search results:</b> ";
for ($i = 1; $i <= $total_pages; $i++)
{
if (isset($_GET['page']) && $_GET['page'] == $i)
{
echo $i . " ";
}
else
{
echo "<a href='test.php?page=$i'>$i</a> ";
}
}
echo "</p>";
// display data in table
// loop through results of database query, displaying them in the table
for ($i = $start; $i < $end; $i++)
{
// make sure that PHP doesn't try to show results that don't exist
if ($i == $total_results) { break; }
// find specific row
$result->data_seek($i);
$row = $result->fetch_row();
// echo out the contents of each row into a table
echo ("Name:$row[1]<br><span class=\"old\"> Age:$row[4]</span><br><span class=\"sold\">Caste:$row[5]</span><br><span class=\"old\">Location:</span><span class=\"sold\">$row[6]</span><br><br>");
}
// close table>
}
else
{
echo "No results to display!";
}
}
// error with the query
else
{
echo "Error: " . $mysqli->error;
}
// close database connection
$mysqli->close();
// display pagination
echo "<p> <b>Your search results:</b> ";
for ($i = 1; $i <= $total_pages; $i++)
{
if (isset($_GET['page']) && $_GET['page'] == $i)
{
echo $i . " ";
}
else
{
echo "<a href='test.php?page=$i'>$i</a> ";
}
}
echo "</p>";
?>

Categories