View Full Version : Display 5 records per page

06-02-2004, 07:54 PM
Hi everybody,
I am using PHP Expert Editor version 3.0.
I want to fetch records from the database but I want to show 5 records per page.
can anyone help.

06-03-2004, 04:01 AM
do you have a current code that needs editing or do u need someone to code the whole script for you? check out some posts in here on how to retrieve info from databases and then go to the PHPFreaks Pagination tutorial located HERE (http://www.phpfreaks.com/quickcode/Pagination/164.php)

06-04-2004, 11:18 AM
I am accepting two values from user on that basis I am searching data from the database But it is showing the following error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in searched_members.php

members.htm file where I am accepting data from user :

<form name="search" method="post" action="/searched_members.php">
Search By
<select name="options" size="1">
<option value="">Select One</option>
<option value="name">Name</option>
<option value="address2">Locality</option>
<option value="city">City</option>
<option value="state">State</option>
Type the content to be searched
<input type="text" name="search_element">
<input type="submit" name="Submit" value="Go">

searched_members.php where code resideds to fetch the data from the database:

// navigation
echo"<a href=\"members.php\" target=\"_self\">Member Search</a> > Search<br>";

search_members($options, $search_element);

function search_members($options, $search_element)
$result = "select * from members where $options like('%$search_element%') order by name, country, state, city, address2";
function limit_display($result)

// limit value for number of records to be shown per page
// query database to find total number of records to display

$limit = 5;
$query_count = $result;
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
$page = 1;
$limitvalue = $page * $limit - ($limit);
$query = $result . " LIMIT $limitvalue, $limit ";
$result = mysql_query($query) or die("Error: " . mysql_error());
$count_result = mysql_num_rows($result);

// Display links at the top to indicate current page and number of pages displayed
$numofpages = ceil($totalrows / $limit);
$to=$from + $count_result-1;

// start 123 next>> table
echo "<table align=\"center\" width=\"90%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr><td width=\"50%\" bgcolor=\"$bg_colour\" align=\"left\">";if($numofpages>1){echo"Showing: $from - $to</td><td width=\"50%\" bgcolor=\"$bg_colour\" align=\"right\"><b>Go to page:</b> ";}

// display previous link if page is not 1
if($page != 1){
$pageprev = $page - 1;
echo("<a href=\"$PHP_SELF?page=$pageprev\"><< PREV".$limit."</a>&nbsp;");

// display page nos if not 1
for($i = 1; $i <= $numofpages; $i++){
if($i == $page)
echo("&nbsp;<a href=\"$PHP_SELF?page=$i&options=$options&search_element=$search_element\">$i</a>&nbsp;");

// display next page link if there is more than one
if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page + 1;
echo("<a href=\"$PHP_SELF?page=$pagenext&options=$options&search_element=$search_element\">NEXT>></a>");
// end 123 next>> table

// if there is a result display it
print "<table border =1 width='100%' cellspacing='0' cellpadding='0'>\n";
while ($a_row = mysql_fetch_object($result))
print "<tr>\n";
print "<td>";
print "\t Name : $a_row->name<br>\n Address : $a_row->address1 <br> Locality :$a_row->address2<br> City : $a_row->city $a_row->pin<br> State : $a_row->state<br>";
if ($a_row->res_phone !="")
print "Ph.(Res) : $a_row->res_phone ";
if ($a_row->off_phone !="")
print " Ph.(Off) : $a_row->res_phone ";
if ($a_row->mobile_phone !="")
print " Mobile : $a_row->res_phone";
print "</td>";
print "</tr>\n";

// Display links at the bottom to indicate current page and number of pages displayed
echo "<table align=\"center\" width=\"90%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr><td bgcolor=\"$bg_colour\" align=\"right\">";

if($numofpages>1){echo"<b>Go to page:</b> ";}

if($page != 1)
$pageprev = $page - 1;
echo("<a href=\"$PHP_SELF?page=$pageprev\"><< PREV</a>&nbsp;");

$numofpages = ceil($totalrows / $limit);
for($i = 1; $i <= $numofpages; $i++){
if($i == $page)
echo("&nbsp;<a href=\"$PHP_SELF?page=$i\">$i</a>&nbsp;");

if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page + 1;
echo("<a href=\"$PHP_SELF?page=$pagenext&options=$options&search_element=$search_element\">NEXT >></a>");

06-04-2004, 12:19 PM
could it be where you have

order by name, country, state, city, address2

shouldnt you only have one ORDER BY statement and a DESC or ASC afterwards?

06-04-2004, 01:07 PM
You can have more than one order by, but it should be in in the form:

ORDER BY col1 DESC, col2 DESC, col3 ASC ect.

06-05-2004, 09:41 AM
"select * from members where $options like '%$search_element%' order by name, country, state, city, address2";

This order by clause is running in MySQL-Front ver. 2.5 independently. But when I run it from PHP file it is displaying following error :

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'like '%%' order by name, country, state, city, address2'