Need some code using php/mysql

They have: 28 posts

Joined: May 2003

Ok, i got this code from a banner rotator script i'm using. How would I go about integrating some code to make one page per 100 rows (queries) on the db. Ex. If they're 500 rows, there would be links on the bottom indicating 1-5 pages with 100 rows per page. (I don't really want to load the server with like 1000s of queries at a time). I've never done this before so if anyone can give me some code/documentation, that would be great.

Thanks,
dave

<?php
$query
= \"SELECT address,datetime, referer FROM stats where id='1'\";
         
$result = mysql_query($query) or die(\"Query failed\");

while (
$line = mysql_fetch_array($result, MYSQL_ASSOC)) {         
            print \"<tr>\";
             foreach (
$line as $col_value) {
                print \"<td height='20' bordercolor='#FFFFFF'><font face='Verdana' size='2'>
$col_value</font></td>\";
             }
          print \"</tr>\";
}
?>

druagord's picture

He has: 335 posts

Joined: May 2003

for the request the SQL should look like this on the firstpage

<?php
\"SELECT address,datetime, referer FROM stats where id='1' LIMIT 0,100\";
?>

this will limit the response from the server to the first 100 rows to get the

<?php
\"SELECT address,datetime, referer FROM stats where id='1' LIMIT 100,100\";
?>

this will give you rows from 100 to 200
here is the sytax for limit

LIMIT startrecord, numrecord

if you have mySQL 4 or greater use this to get the total number of record and then you can display your links based on that

<?php
\"SELECT SQL_CALC_FOUND_ROWS address,datetime, referer FROM stats where id='1' LIMIT 0,100\";
\"Select FOUND_ROWS()\";
?>

IF , ELSE , WHILE isn't that what life is all about

They have: 28 posts

Joined: May 2003

Yeah I knew about the LIMIT option but the # of rows is dynamic so how would I get it to have like page numbers in the bottom to print a certain number of rows when clicked.

druagord's picture

He has: 335 posts

Joined: May 2003

by using the select Found_rows() you will have the total numbers of row you divid it by 100 round up and you get how many link you need to put. then on link 2 put min limit 100 on link 3 put min limit 200 etc...

IF , ELSE , WHILE isn't that what life is all about

They have: 28 posts

Joined: May 2003

Ah ok... I'll try that.

thanks

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.