Hi
I am new to php and i`m enjoying learning it.
I have just started on databases and come across a slight problem:
I need to display records of 10 the have a next and prev button to display the remainder of the records.
I have seached all way through this forum but the code i have come across is all Chinese to me - here is the code i have so far:
<?
$server= "myserver";
$user= "myaccount";
$password= "pass";
$database= "database1";
$table= "table1";
MYSQL_CONNECT($server, $user, $password) or die ( "<H3>Server unreachable</H3>");
MYSQL_SELECT_DB($database) or die ( "<H3>Database non existent</H3>");
$result=MYSQL_QUERY( "SELECT * FROM $table order by name ");
if(mysql_num_rows($result)) {
// it is true, so let's print the results to the browser
while($row = mysql_fetch_row($result))
{
print (" $row[0] "); ?><? print (" $row[1] "); ?><? print (" $row[2] ");
?>
<?
}
} else {
// false, no results
}
?>
thats the code i am using so could someone please help me where to put the code for displaying the next records etc...
Thank you very much
Lee
The PHP Newbie !
Please Help with this problem
Moderator: General Moderators
- mydimension
- Moderator
- Posts: 531
- Joined: Tue Apr 23, 2002 6:00 pm
- Location: Lowell, MA USA
- Contact:
here is a tutorial that is easy to follow, provides a simple script structure that is quite expandable: http://codewalkers.com/tutorials.php?show=4
Ok i have manged to get the next previous buttons working but say 20 records are shown then when clicking the next button theres no more records to show ! so i need not to display the next button after the last record is shown - can anyone help me with this problem ?
The code i`m using is this:
$prevlimit=$limit-5;
if ($prevlimit<0) $prevlimit=0;
if ($limit > 4 )
echo "<a href=\"$_SERVER[PHP_SELF]?search=$search&limit=$prevlimit\>previous 5</a>";
else
echo " ";
$nextlimit=$limit+5;
if ($limit < $no_of_records )
echo "<a href=\"$_SERVER[PHP_SELF]?search=$search&limit=$nextlimit\">next 5</a>";
else
echo " ";
?>
Thanks
The code i`m using is this:
$prevlimit=$limit-5;
if ($prevlimit<0) $prevlimit=0;
if ($limit > 4 )
echo "<a href=\"$_SERVER[PHP_SELF]?search=$search&limit=$prevlimit\>previous 5</a>";
else
echo " ";
$nextlimit=$limit+5;
if ($limit < $no_of_records )
echo "<a href=\"$_SERVER[PHP_SELF]?search=$search&limit=$nextlimit\">next 5</a>";
else
echo " ";
?>
Thanks
the querywill return the number of records in tablename. You can use this to determine the upper limit.
Code: Select all
SELECT count(*) FROM tablenameit's explained in the last section of the tutorial mydimension pointed you to 
http://codewalkers.com/tutorials/4/5/
http://codewalkers.com/tutorials/4/5/