Re: [PHP] Making Multiple Pages

2002-05-16 Thread J Smith


You should also add an ORDER BY clause in there, as the SQL standard doesn't 
guarantee the order that rows are retrieved in. There's a chance that 
you'll get, say, 20 rows on the first page, go to the second page and get 
some of the rows you've already seen on the first page. If you use an ORDER 
BY, you'll at least guarantee that you'll get them in the same order each 
time.

J


Kevin Stone wrote:

> $query = "SELECT * FROM mytable LIMIT $i, 20";
> 
> Where 20 is the number of rows to retrieve and $i is the starting row.
> 
> By incrementing $i + 20 you can do next, prev buttons, or parse the total
> number of rows into page links (prev - 1, 2, 3, 4, 5, 6.. 10.. 20 - next).
> 
> Search www.mysql.com for more information about using LIMIT in your
> queries.
> 
> -Kevin
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Making Multiple Pages

2002-05-16 Thread Cal Evans

Do a google search for ADODB. It's a PHP database abstraction layer. It has
built in 'pagination' methods (Previous X, next X) along with an example of
how to use them.

=C=

*
* Cal Evans
* Journeyman Programmer
* Techno-Mage
* http://www.calevans.com
*


-Original Message-
From: Jason Soza [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 16, 2002 1:31 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Making Multiple Pages


I have some ideas on how this should be done, but I'm at work and can't
really test them, so I was thinking maybe I could run it by you all and
maybe get some feedback and/or new ideas.

I have a PHP/MySQL-generated page that displays image thumbnails.
Currently, I have a loop that makes a table and table rows, fills the
rows with the thumbnails, then when there's no more information, it
completes whatever row it's on with blank 's, then closes the table.

This was working fine, but my site is actually attracting more traffic
than I originally thought, and I'm getting more image submissions. It's
getting to where it's no longer practical to arrange all the thumbnails
onto one page, I need to have like 25 on one page, then have the script
create a link at the bottom so users can click and see the next 25.

I'm thinking I need to use some kind of row count language in the
script, i.e. first count how many rows are in the MySQL table, if it's
less than 25, just display them all. If there's more than 25, display
only 1 - 25, then create a link to view 26 - 50, etc.

Is that what I need to be looking into? Any other ideas would be
appreciated. Thanks!

Jason Soza


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Making Multiple Pages

2002-05-16 Thread Kevin Stone

One way to get it started would be to work strictly within the links.  Don't
initilize $i unless it is not set (which logically would mean your visitng
the page for the first time).  So..

if (!isset($_GET['i']))
$i = 0;
else
$i += 20;

Another way would be to extract the number of total rows, divide by 20, and
build a list of links in a for() loop.
$num_rows = mysql_num_rows($sql);
$num_pages = floor($num_rows/20);
for ($i=0; $i
To: "Kevin Stone" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, May 16, 2002 1:15 PM
Subject: Re: [PHP] Making Multiple Pages


> Great! I think that's the SQL function I needed.
>
> Now for the PHP part - I'm a bit fo a newbie at writing code, so bear
> with me here. My query string is currently something like:
>
> $sql = mysql_query("SELECT * FROM mytable WHERE color=$color");
>
> So I would modify that to read:
>
> $sql = mysql_query("SELECT * FROM mytable WHERE color=$color LIMIT $i,
> 25");
>
> Where $i = 1 To get just the first 25 records. I think I'm confused on
> how to set $i and create links. Would I just initially set $i = "1";
> then make links that point to:
>
> myscript.php?color=red&i=25
>
> Then have a $_GET['i'] variable in my script and set $i equal to that?
>
> Your help is appreciated. Thanks again.
>
> Jason Soza
>
> - Original Message -
> From: "Kevin Stone" <[EMAIL PROTECTED]>
> Date: Thursday, May 16, 2002 10:53 am
> Subject: Re: [PHP] Making Multiple Pages
>
> > $query = "SELECT * FROM mytable LIMIT $i, 20";
> >
> > Where 20 is the number of rows to retrieve and $i is the starting row.
> >
> > By incrementing $i + 20 you can do next, prev buttons, or parse
> > the total
> > number of rows into page links (prev - 1, 2, 3, 4, 5, 6.. 10.. 20 -
> > next).
> >
> > Search www.mysql.com for more information about using LIMIT in
> > your queries.
> >
> > -Kevin
> >
> > - Original Message -
> > From: "Jason Soza" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Thursday, May 16, 2002 12:31 PM
> > Subject: [PHP] Making Multiple Pages
> >
> >
> > > I have some ideas on how this should be done, but I'm at work
> > and can't
> > > really test them, so I was thinking maybe I could run it by you
> > all and
> > > maybe get some feedback and/or new ideas.
> > >
> > > I have a PHP/MySQL-generated page that displays image thumbnails.
> > > Currently, I have a loop that makes a table and table rows,
> > fills the
> > > rows with the thumbnails, then when there's no more information, it
> > > completes whatever row it's on with blank 's, then closes
> > the table.
> > >
> > > This was working fine, but my site is actually attracting more
> > traffic> than I originally thought, and I'm getting more image
> > submissions. It's
> > > getting to where it's no longer practical to arrange all the
> > thumbnails> onto one page, I need to have like 25 on one page,
> > then have the script
> > > create a link at the bottom so users can click and see the next 25.
> > >
> > > I'm thinking I need to use some kind of row count language in the
> > > script, i.e. first count how many rows are in the MySQL table,
> > if it's
> > > less than 25, just display them all. If there's more than 25,
> > display> only 1 - 25, then create a link to view 26 - 50, etc.
> > >
> > > Is that what I need to be looking into? Any other ideas would be
> > > appreciated. Thanks!
> > >
> > > Jason Soza
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Making Multiple Pages

2002-05-16 Thread Jason Soza

Great! I think that's the SQL function I needed.

Now for the PHP part - I'm a bit fo a newbie at writing code, so bear 
with me here. My query string is currently something like:

$sql = mysql_query("SELECT * FROM mytable WHERE color=$color");

So I would modify that to read:

$sql = mysql_query("SELECT * FROM mytable WHERE color=$color LIMIT $i, 
25");

Where $i = 1 To get just the first 25 records. I think I'm confused on 
how to set $i and create links. Would I just initially set $i = "1"; 
then make links that point to:

myscript.php?color=red&i=25

Then have a $_GET['i'] variable in my script and set $i equal to that?

Your help is appreciated. Thanks again.

Jason Soza

- Original Message -
From: "Kevin Stone" <[EMAIL PROTECTED]>
Date: Thursday, May 16, 2002 10:53 am
Subject: Re: [PHP] Making Multiple Pages

> $query = "SELECT * FROM mytable LIMIT $i, 20";
> 
> Where 20 is the number of rows to retrieve and $i is the starting row.
> 
> By incrementing $i + 20 you can do next, prev buttons, or parse 
> the total
> number of rows into page links (prev - 1, 2, 3, 4, 5, 6.. 10.. 20 -
> next).
> 
> Search www.mysql.com for more information about using LIMIT in 
> your queries.
> 
> -Kevin
> 
> - Original Message -
> From: "Jason Soza" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, May 16, 2002 12:31 PM
> Subject: [PHP] Making Multiple Pages
> 
> 
> > I have some ideas on how this should be done, but I'm at work 
> and can't
> > really test them, so I was thinking maybe I could run it by you 
> all and
> > maybe get some feedback and/or new ideas.
> >
> > I have a PHP/MySQL-generated page that displays image thumbnails.
> > Currently, I have a loop that makes a table and table rows, 
> fills the
> > rows with the thumbnails, then when there's no more information, it
> > completes whatever row it's on with blank 's, then closes 
> the table.
> >
> > This was working fine, but my site is actually attracting more 
> traffic> than I originally thought, and I'm getting more image 
> submissions. It's
> > getting to where it's no longer practical to arrange all the 
> thumbnails> onto one page, I need to have like 25 on one page, 
> then have the script
> > create a link at the bottom so users can click and see the next 25.
> >
> > I'm thinking I need to use some kind of row count language in the
> > script, i.e. first count how many rows are in the MySQL table, 
> if it's
> > less than 25, just display them all. If there's more than 25, 
> display> only 1 - 25, then create a link to view 26 - 50, etc.
> >
> > Is that what I need to be looking into? Any other ideas would be
> > appreciated. Thanks!
> >
> > Jason Soza
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Making Multiple Pages

2002-05-16 Thread Kevin Stone

$query = "SELECT * FROM mytable LIMIT $i, 20";

Where 20 is the number of rows to retrieve and $i is the starting row.

By incrementing $i + 20 you can do next, prev buttons, or parse the total
number of rows into page links (prev - 1, 2, 3, 4, 5, 6.. 10.. 20 - next).

Search www.mysql.com for more information about using LIMIT in your queries.

-Kevin

- Original Message -
From: "Jason Soza" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, May 16, 2002 12:31 PM
Subject: [PHP] Making Multiple Pages


> I have some ideas on how this should be done, but I'm at work and can't
> really test them, so I was thinking maybe I could run it by you all and
> maybe get some feedback and/or new ideas.
>
> I have a PHP/MySQL-generated page that displays image thumbnails.
> Currently, I have a loop that makes a table and table rows, fills the
> rows with the thumbnails, then when there's no more information, it
> completes whatever row it's on with blank 's, then closes the table.
>
> This was working fine, but my site is actually attracting more traffic
> than I originally thought, and I'm getting more image submissions. It's
> getting to where it's no longer practical to arrange all the thumbnails
> onto one page, I need to have like 25 on one page, then have the script
> create a link at the bottom so users can click and see the next 25.
>
> I'm thinking I need to use some kind of row count language in the
> script, i.e. first count how many rows are in the MySQL table, if it's
> less than 25, just display them all. If there's more than 25, display
> only 1 - 25, then create a link to view 26 - 50, etc.
>
> Is that what I need to be looking into? Any other ideas would be
> appreciated. Thanks!
>
> Jason Soza
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php