Jump to content

printing our an array on multiple pages


mATOK

Recommended Posts

Hey there, I hope that someone can give me a hand. I have a multi dimensional array that I would like to print out on multiple pages, 10 elements at a time.

 

Here is what I grab from my SQL -

 

$q="SELECT * FROM print_notes ORDER BY effective_date DESC";

$rez=mysql_query($q) or die (mysql_error());

 

I then proceed to iterate through the array printing out various elements...

 

while ($i = mysql_fetch_array($rez)

 

Now I want only 10 elements per page and am unsure how to go about this... I was thinking perhaps of adding a count like:

 

while ($i = mysql_fetch_array($rez) AND $num < 10) {

 

                                $num++;

But I don't know how to start the next page at the 11th element in the array.

 

Any help is appreciated.

 

 

Link to comment
https://forums.phpfreaks.com/topic/50500-printing-our-an-array-on-multiple-pages/
Share on other sites


your thinkin bout it a little backwards... dont limit the while()... limit the query...

 

$result=db_query("SELECT * FROM updater_photos WHERE `category`='1'");
$num=mysql_num_rows($result);
if(!is_numeric($_GET

)) $page=1;
else $page=$_GET

;
$limit=12;
$start = $page * $limit - ($limit);
$result = db_query("SELECT * FROM updater_photos WHERE ORDER BY id LIMIT $start, $limit");

 

then you just ?page=2

  • 2 weeks later...

Ok I got this far

 

$num = mysql_num_rows($rez);

        if(!is_numeric($_GET


)) { $page=1; }

        else $page=$_GET


;

        $limit=12;

        $start = $page * $limit - ($limit);

        $result = mysql_query("SELECT * FROM print_notes ORDER BY print_note_num LIMIT $start, $limit") or die (mysql_error());

 

        while ($i = mysql_fetch_array($result)) {

 

how would I go about creating a page2?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.