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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying SQL rows 5 at a time

Status
Not open for further replies.

clownkevin

Technical User
Dec 6, 2000
11
GB
I have a search page which retrieves data from sql. This is written to the page as follows:

for ($i=0; $i<= $num-1; $i++) {
$row = mysql_fetch_object($r);
print &quot;<h3>$row->name</h3>&quot;.
&quot;<p>$row->town<br>&quot;.
&quot;$row->county<br>&quot;;
if($row->contact) {print &quot;<b>email: <a href='mailto:$row->contact?subject=I found you on Hotel Heaven'>$row->contact</a></b><br>&quot;;}
if($row->web) {print &quot;<b>Website: <a href='cgi-bin/axs/ax.pl?$row->web' target=_blank>$row->web</a></b><br>&quot; ;}
print &quot;<b>Telephone:</b> $row->telephone<hr>&quot;;
}}

if($num>50) {print &quot;<br><br><h2>Oops!</h2><p>Your search has returned more than 50 results! Please click <a href=search.php3>Here</a> to redefine.<hr> &quot; ;} }


I can't figure out how to display a few rows from the result, with a link which would then display the next batch...

Probably a bit of a newbie question, but please help!

Jim
 
when querying the mysql database u have the option of using limit and offset. U want on the first page 50 results, so use: mysql_query(&quot;SELECT * FROM table WHERE yaddayadda LIMIT 0, 50&quot;);
I really dont know if this is the right way of using limit (in postgres it is).
Well now u make the 0 and the 50 variable, when going to the second page u post limit as 50 and offset as 50.
Now records 50 to 100 will be retrieved.
I hope this answers ure question.
(For the correct use of limit look at mysql.com or mysql.org) mcvdmvs
-- &quot;It never hurts to help&quot; -- Eek the Cat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top