Page 1 of 1

Need Help Displaying the Contents from the table

Posted: Thu May 13, 2004 1:36 pm
by Kingo
I used Dream weaver to bind the database and display the contents from the table. The problem is I CAN DISPLAY only 10 rows per page. I want to have a next Button which shows the other 10 rows in another page.

<?php

$maxRows_rs_contact = 10;

$pageNum_rs_contact = 0;

if (isset($HTTP_GET_VARS['pageNum_rs_contact']))
{
$pageNum_rs_contact = $HTTP_GET_VARS['pageNum_rs_contact'];
}
$startRow_rs_contact = $pageNum_rs_contact * $maxRows_rs_contact;

//mysql_select_db($database_dbconnect, $dbconnect);
$query_rs_contact = "SELECT * FROM contact";
$query_limit_rs_contact = sprintf("%s LIMIT %d, %d", $query_rs_contact, $startRow_rs_contact, $maxRows_rs_contact);
$rs_contact = mysql_query($query_limit_rs_contact, $connect) or die(mysql_error());
$row_rs_contact = mysql_fetch_assoc($rs_contact);

if (isset($HTTP_GET_VARS['totalRows_rs_contact'])) {
$totalRows_rs_contact = $HTTP_GET_VARS['totalRows_rs_contact'];
} else {
$all_rs_contact = mysql_query($query_rs_contact);
$totalRows_rs_contact = mysql_num_rows($all_rs_contact);
}
$totalPages_rs_contact = ceil($totalRows_rs_contact/$maxRows_rs_contact)-1;
?>
<table border="1">
<tr>
<td>Name</td>
<td>Phone</td>
<td>Email</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_rs_contact['Name']; ?></td>
<td><?php echo $row_rs_contact['Phone']; ?></td>
<td><?php echo $row_rs_contact['Email']; ?></td>
</tr>
<?php } while ($row_rs_contact = mysql_fetch_assoc($rs_contact)); ?>
</table>

Posted: Thu May 13, 2004 1:54 pm
by launchcode
So that's what Dreamweaver PHP code looks like!
Ick :)

Anyway, in looking at the code I see no reason at all why you cannot do what you want. You just need a link in your page that sets the pageNum_rs_contact.

Code: Select all

<?php
$nextpage = $pageNum_rs_contact + 1;
echo "<a href="script.php?pageNum_rs_contact=$nextpage">Next Page</a>";
?>

Posted: Thu May 13, 2004 1:58 pm
by Kingo
What should i substitue for script.php. My page name is form1.php. If i use this it is not displaying

Posted: Thu May 13, 2004 5:49 pm
by launchcode
Post the error you get (if any).

It should be substituted for whatever your script is called (you never said in your original post).

Try changing this part at the start of your script:

Code: Select all

$pageNum_rs_contact = 0;

if (isset($HTTP_GET_VARS['pageNum_rs_contact']))
{
$pageNum_rs_contact = $HTTP_GET_VARS['pageNum_rs_contact'];
} 

to

if (isset($_GET['pageNum_rs_contact']))
{
$pageNum_rs_contact = $_GET['pageNum_rs_contact'];
}
else
{
$pageNum_rs_contact = 0;
}
Also echo out the value of $pageNum_rs_contact, or the SQL query itself so you can start debugging the thing.

Posted: Fri May 14, 2004 4:45 pm
by Kingo
It still wont work.....I cant see the error..It gets redirected to my first page ina blink

Posted: Fri May 14, 2004 4:54 pm
by tim
just FYI

theres a script in the tutorials section that does this.

it does have javascript tho =[