Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.