Page 1 of 1

Plz help--Links dont work when i display contents from table

Posted: Sun May 16, 2004 4:35 pm
by Kingo
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>

Posted: Sun May 16, 2004 5:26 pm
by reverend_ink
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>

Posted: Sun May 16, 2004 5:46 pm
by Kingo
Thanx very much..........but the links still doesnt work..i mean when i click the second page link..the data doesnt get displayed..i still see the first page data

Posted: Sun May 16, 2004 5:58 pm
by reverend_ink
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>

Posted: Sun May 16, 2004 6:00 pm
by reverend_ink
If you need please feel free to IM me and I will help you implement this and get it working.

Posted: Sun May 16, 2004 7:19 pm
by Kingo
I used your code..but still cant get it to work
I still get the first page displayed even if i click the second, third, fourth url's...Your help is really appreciated

Posted: Sun May 16, 2004 7:26 pm
by Kingo
Or is there any other code you can give it to me...which connects the table in a databse and displayes the rows page wise.

Posted: Sun May 16, 2004 7:32 pm
by Kingo
Or is there any other code you can give it to me...which connects the table in a databse and displayes the rows page wise.