Jump to content

Recommended Posts

Posted

If it's MySQL you're taking your data from, the LIMIT clause may be very useful to you.

 

$perPage = 20;
$pageNum = (int)$_GET['pagenum'];

if( $pagenum < 0 ) { $pageNum = 0; }

$from = $pageNum * $perPage;

$query = 'SELECT * FROM my_table LIMIT '.$from.', '.$perPage;
// mysql connection stuffs...
$data = mysql_query($query);

echo '</pre><table>';
while( $row = mysql_fetch_assoc($data) ) {
 echo '';
 var_dump($row);
 echo '';
}
echo '</table>';<br>?&g

 

The while loop is pretty generic and won't make things nice, but you (hopefully) get the idea.

 

Hello

:-Dave

 

As always, code is untested and has no guarantees of any kind.

Posted
If you're grabbing from MySQL or suchlike, use the limit function of SQL... easiest and simplest way! :)

 

I am using MySQL - do you have this in an example.

Posted

SELECT * FROM table WHERE thing=true LIMIT 10;

 

gets the first ten records returned only

 

SELECT * FROM table WHERE thing=true LIMIT 10, 10;

 

gets ten records from row eleven onwards (note: add an ORDER BY if you want to be able to predict what you'll be getting).

Posted
I am using MySQL - do you have this in an example.

 

you can always create a chunk of php code around your main loop to return pages of information - e.g. off the top of my head (from things I've done in the past):

----------------------------------

$sql = "SELECT * FROM mytable ";

 

if(($pageStart == "")||($pageStart < 0)){

$pageStart = 0;

}

 

 

$sql .= "LIMIT $pageStart,50";

 

$result = @mysql_query($sql);

 

while($resultArray = @mysql_fetch_array($result)){

// Grab a new row of data

// Do your grab / display routine here

$pageStart++;

}

 

// To create a google-esque page list

$sql = "SELECT * FROM tablename";

$PageNum = 0; // Set First Page

$numPages = 0; // Set zero number of pages to display

$result = @mysql_query($sql);

$numresults = @mysql_num_rows($result);

 

while($numPages <= $numresults){

print " $PageNum ";

$PageNum++;

$numPages = $numPages + 50;

}

 

------------------------------

 

This will create a page with fifty entries per page, if you enter the page with no starting point it will display from the beginning...

 

hope that helps a bit - PM me if you need a bit more info. :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...