Need Help Displaying the Contents from the table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Kingo
Forum Contributor
Posts: 146
Joined: Thu Jun 03, 2004 9:38 am

Need Help Displaying the Contents from the table

Post 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>
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post 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>";
?>
Kingo
Forum Contributor
Posts: 146
Joined: Thu Jun 03, 2004 9:38 am

Post by Kingo »

What should i substitue for script.php. My page name is form1.php. If i use this it is not displaying
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post 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.
Kingo
Forum Contributor
Posts: 146
Joined: Thu Jun 03, 2004 9:38 am

Post by Kingo »

It still wont work.....I cant see the error..It gets redirected to my first page ina blink
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

just FYI

theres a script in the tutorials section that does this.

it does have javascript tho =[
Post Reply