Page 1 of 1

Please Help with this problem

Posted: Sun Oct 20, 2002 9:49 am
by leebo
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 !

Posted: Sun Oct 20, 2002 2:10 pm
by mydimension
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

Posted: Sun Dec 01, 2002 4:47 am
by leebo
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

Posted: Sun Dec 01, 2002 7:09 am
by volka
the query

Code: Select all

SELECT count(*) FROM tablename
will return the number of records in tablename. You can use this to determine the upper limit.

Posted: Sun Dec 01, 2002 2:03 pm
by leebo
sorry but i dont understand where to add this ?? :? i`m new to php and databases and learning it quite frustrating :oops:

Posted: Sun Dec 01, 2002 11:43 pm
by volka
it's explained in the last section of the tutorial mydimension pointed you to ;)
http://codewalkers.com/tutorials/4/5/