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>
Plz help--Links dont work when i display contents from table
Moderator: General Moderators
-
reverend_ink
- Forum Contributor
- Posts: 151
- Joined: Sun Apr 20, 2003 1:18 am
- Location: Las Vegas | London
Here you go
You were missing a ();
<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 Name 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); //was missing the () here
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); //was missing the () here
echo "<a href=\"$url\">Next</a>\n";
}
?>
</body>
</html>
You were missing a ();
<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 Name 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); //was missing the () here
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); //was missing the () here
echo "<a href=\"$url\">Next</a>\n";
}
?>
</body>
</html>
-
reverend_ink
- Forum Contributor
- Posts: 151
- Joined: Sun Apr 20, 2003 1:18 am
- Location: Las Vegas | London
Just checked it with a table oif mine that had 19 entries.
Use this as it does work
<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 Name FROM header ");
$total_records = mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);
mysql_free_result($result);
if (!isset($screen))
{
$screen = 0; // Everything was being reset to 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); //was missing the () here
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); //was missing the () here
echo "<a href=\"$url\">Next</a>\n";
}
?>
</body>
</html>
Use this as it does work
<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 Name FROM header ");
$total_records = mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);
mysql_free_result($result);
if (!isset($screen))
{
$screen = 0; // Everything was being reset to 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); //was missing the () here
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); //was missing the () here
echo "<a href=\"$url\">Next</a>\n";
}
?>
</body>
</html>
-
reverend_ink
- Forum Contributor
- Posts: 151
- Joined: Sun Apr 20, 2003 1:18 am
- Location: Las Vegas | London