Plz help--Links dont work when i display contents from table
Posted: Sun May 16, 2004 4:35 pm
Only the first 5 rows of the table gets displayed....Any help is really appreciated
<html>
<head>
<title>Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$hostname = 'localhost';
$username ='abc';
$password ='123';
$dbName = 'phptest';
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect");
@MYSQL_SELECT_DB("$dbName") OR DIE("Unable to select database");
$rows_per_page = 5;
$result = mysql_query("SELECT * FROM header");
$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;
$result = mysql_query("SELECT Name FROM header LIMIT $start, $rows_per_page");
$rows = mysql_num_rows($result);
for ($i = 0; $i < $rows; $i++) {
$Name = mysql_result($result, $i, 0);
echo "$Name<br>\n";
}
echo "<p><hr></p>\n";
// let's create the dynamic links now
if ($screen > 0) {
$url = "example.php?screen=" . $screen - 1;
echo "<a href=\"$url\">Previous</a>\n";
}
// page numbering links now
for ($i = 0; $i < $pages; $i++) {
$url = "example.php?screen=" . $i;
echo " | <a href=\"$url\">$i</a> | ";
}
if ($screen < $pages) {
$url = "example.php?screen=" . $screen + 1;
echo "<a href=\"$url\">Next</a>\n";
}
?>
</body>
</html>
<html>
<head>
<title>Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$hostname = 'localhost';
$username ='abc';
$password ='123';
$dbName = 'phptest';
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect");
@MYSQL_SELECT_DB("$dbName") OR DIE("Unable to select database");
$rows_per_page = 5;
$result = mysql_query("SELECT * FROM header");
$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;
$result = mysql_query("SELECT Name FROM header LIMIT $start, $rows_per_page");
$rows = mysql_num_rows($result);
for ($i = 0; $i < $rows; $i++) {
$Name = mysql_result($result, $i, 0);
echo "$Name<br>\n";
}
echo "<p><hr></p>\n";
// let's create the dynamic links now
if ($screen > 0) {
$url = "example.php?screen=" . $screen - 1;
echo "<a href=\"$url\">Previous</a>\n";
}
// page numbering links now
for ($i = 0; $i < $pages; $i++) {
$url = "example.php?screen=" . $i;
echo " | <a href=\"$url\">$i</a> | ";
}
if ($screen < $pages) {
$url = "example.php?screen=" . $screen + 1;
echo "<a href=\"$url\">Next</a>\n";
}
?>
</body>
</html>