Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

making multiple pages

Status
Not open for further replies.

PhoenixDown

Programmer
Jul 2, 2001
279
CA
im making a guestbook and in my control i have an option for max entries per page. currently the option in my mysql db is set to 10. so can someone help me make something that will display xx entries per page and to display the pages at the bottom of my guestbook? i really need help making this. thanks.
 
You need to look at the LIMIT clause of the SELECT statement in MySQL.

"SELECT * FROM foo LIMIT 10" will return the first ten rows of the records provided by the select.

"SELECT * FROM foo LIMIT 10,10" will return ten records from the SELECT, starting with row 11. (Apparently, MySQL counts from zero).

______________________________________________________________________
My God! It's full of stars!
______________________________________________________________________
 
Do you need help with getting the data out (help with PHP's mysql family of functions) or with formatting the output? ______________________________________________________________________
My God! It's full of stars!
______________________________________________________________________
 
I did this on my pages. It might not be the best, but it works fine for me:
<?
$incr=10;
if(!$start){
$start=0;
}
$end=0;
/////change this so that it's one column that you have in the table
$q=&quot;SELECT message FROM post&quot;;
/////
$res=mysql_query($q);
$amount=mysql_num_rows($res);

$i=1;
while($amount>$end){
print(&quot;<font size=\&quot;5\&quot;>&quot;);
if($end==$start){
print(&quot;<b>$i</b>&quot;);
} else{
//////////////////change view_posts to the name of the page that you display the posts on.
print(&quot;<a href=\&quot;index.php?ba=view_posts&start=$end\&quot;>$i</a> &quot;);
//////////////////
}
print(&quot;</font>&quot;);
$end+=$incr;
$i++;
}
?>

---Did you say full of stars??? Like, enough for me too?!!!

Rick If I have helped you just click the first link below to let me know :)
 
ristmo2001, i'm sorry i couldnt get yours to work on my script.

sleipnir214, thanks you very mucgh, i only need help with the output.
 
I'm not sure why not. You changed the two words below?

$q=&quot;SELECT message FROM post&quot;;

The first one is the row name and the second is the table name.

Oh I know why it's working. You are not using the same querry as me. Sorry I didn't provide it the first time.
Here:

$q=&quot;SELECT name,message FROM post ORDER BY name LIMIT $start,$incr&quot;;

That's the main thing you must have. Again, change the names to ones that you use.

Then, the rest of the stuff, all the printing info goes here:

$res=mysql_query($q);
while($row=mysql_fetch_array($res)){
print($row[&quot;name&quot;]);//or whatever the name of the row is instead of &quot;name&quot;.
}

Rick If I have helped you just click the first link below to let me know :)
 
i still coudln't get it to work. it displays the pages, but it doesn't put the guestbook entries into those pages.
 
Can you post your code so I can see why not?

Rick If I have helped you just click the first link below to let me know :)
 
Sorry, I thought I said yes a long time ago.
My email is: ristmo_2000_2000@yahoo.com
Rick If I have helped you just click the first link below to let me know :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top