displaying limited number of records in each page

Codes here !

Moderators: macek, egami, gesf

anand
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Dec 04, 2002 8:07 am

displaying limited number of records in each page

Postby anand » Wed Dec 04, 2002 8:18 am

Hello

I have 5 records in my DB I want to see 2 records in each page, when I execute this script it only shows the first two records, it never displays next records irrespective of pressing the buttons 0,1,next , and I never get previous butoon ,,, why?

Can somebody please help me

<?php

$db="myDB";
mysql_connect ("localhost","","") or die ("Can't connect!");
mysql_select_db ("myDB") or die ("Can't open database!");
// query to get the number of records
$sql = "SELECT name, email FROM mttable";
$result = mysql_db_query("contactDB",$sql) or die("Couldn't connect ERROR");
$rows_per_page = 2;
$total_records = mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);
mysql_free_result($result);


if (!isset($screen)){
$screen = 0;}
$start = $screen * $rows_per_page;
$sql = "SELECT name,email FROM mytable ";
$sql .= "LIMIT $start, $rows_per_page";
$result = mysql_query($sql);
$rows = mysql_num_rows($result);
echo "$rows\n";

for ($i = 0; $i < $rows; $i++) {
$name = mysql_result($result, $i, 0);
$email = mysql_result($result, $i,1);
echo "Name = $name<br>\n";
echo "Email = $email<br>\n";
}

echo "<p><hr></p>\n";
if ($screen > 0) {
$url = "index1.php?screen=" . $screen - 1;
echo "<a href=\"$url\">Previous</a>\n";
}
// page numbering links now
for ($i = 0; $i < $pages; $i++) {
$url = "index1.php?screen=" . $i;
echo " | <a href=\"$url\">$i</a> | ";
}
if ($screen < $pages) {
$url = "index1.php?screen=" . $screen + 1;
echo "<a href=\"$url\">Next</a>\n";
}

?>

da9nlc
New php-forum User
New php-forum User
Posts: 21
Joined: Sun Feb 23, 2003 11:58 pm
Contact:

Similar problem

Postby da9nlc » Thu Apr 03, 2003 8:13 am

Hi I see you didnt get a reply to your post Im getting the same. I have had the same problem getting the first set of results and when I click on next it just seems to restart the sequence and giving me error I have not filled in details, showing the variables arent being sent and just going to page 2 with results 10 to 20.

I hope you dont mind me asking did you ever find out what the problem is?


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 1 guest

cron