By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,795 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,795 IT Pros & Developers. It's quick & easy.

"Paging" (First/Previous/Next/Last to limit # of listings per page)

P: n/a
Wm
I'm trying to get a handle on the best way to handle setting up my listings
so that I display groups of about 25 records per page. I currently have a
page that returns over 1,000 names/addresses, which is obviously not very
efficient. Does anyone have any suggestions on the best way to approach
this, or recommendations on what pitfalls to avoid? I'm assuming that I need
to be able to count the total number of records that match the search
criteria, possibly at the top of the page before any HTML output, then find
some way to identify/track the first record, next record, etc...? I know I
should replace my existing query with something that limits it to about 25
records at a time, right?

Thanx in advance for any/all suggestions!
Wm

<?php include('dbconnect.php');
echo "<TABLE width=\"100%\" align=\"center\" border=\"0\"
cellpadding=\"0\" cellspacing=\"0\">";
$query="SELECT * from artists
WHERE mentor='0'
ORDER BY country DESC, state ASC, city ASC, lastname ASC";
$result=mysql_query($query) or die(mysql_error("Could not execute
query."));
while($row = mysql_fetch_array($result)) {
$artistID = $row['artistID'];
$firstname = (ucwords(strtolower($row['firstname'])));
$lastname = (ucwords(strtolower($row['lastname'])));
$mentor= $row['mentor'];
$city= (ucwords(strtolower($row['city'])));
$state= (strtoupper($row['state']));
$country= (strtoupper($row['country']));
//....etc....
echo "
<TD align=\"left\" valign=\"top\" width=\"50%\"><FONT size=\"2\"
face=\"Arial, Helvetica, sans-serif\">
<A HREF=\"javascript:;\"
onClick=\"openProfile('artist.php?artistID=".$arti stID.
"','Artist','resizable=yes,width=750,height=400')\ ">".$firstname."
".$lastname."</A></FONT></TD>
//....etc....


Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I don't know if this is an option for you, but you could try ADODB, its got
a great pager built in,

http://php.weblogs.com/ADOdb
http://phplens.com/adodb/tutorial.im....previous.html

hth

--b

"Wm" <LA*******@hotmail.com> wrote in message
news:pn**********************@news.easynews.com...
I'm trying to get a handle on the best way to handle setting up my listings so that I display groups of about 25 records per page. I currently have a
page that returns over 1,000 names/addresses, which is obviously not very
efficient. Does anyone have any suggestions on the best way to approach
this, or recommendations on what pitfalls to avoid? I'm assuming that I need to be able to count the total number of records that match the search
criteria, possibly at the top of the page before any HTML output, then find some way to identify/track the first record, next record, etc...? I know I should replace my existing query with something that limits it to about 25
records at a time, right?

Thanx in advance for any/all suggestions!
Wm

<?php include('dbconnect.php');
echo "<TABLE width=\"100%\" align=\"center\" border=\"0\"
cellpadding=\"0\" cellspacing=\"0\">";
$query="SELECT * from artists
WHERE mentor='0'
ORDER BY country DESC, state ASC, city ASC, lastname ASC";
$result=mysql_query($query) or die(mysql_error("Could not execute
query."));
while($row = mysql_fetch_array($result)) {
$artistID = $row['artistID'];
$firstname = (ucwords(strtolower($row['firstname'])));
$lastname = (ucwords(strtolower($row['lastname'])));
$mentor= $row['mentor'];
$city= (ucwords(strtolower($row['city'])));
$state= (strtoupper($row['state']));
$country= (strtoupper($row['country']));
//....etc....
echo "
<TD align=\"left\" valign=\"top\" width=\"50%\"><FONT size=\"2\"
face=\"Arial, Helvetica, sans-serif\">
<A HREF=\"javascript:;\"
onClick=\"openProfile('artist.php?artistID=".$arti stID.
"','Artist','resizable=yes,width=750,height=400')\ ">".$firstname."
".$lastname."</A></FONT></TD>
//....etc....

Jul 16 '05 #2

P: n/a
"Wm" <LA*******@hotmail.com> wrote in message news:<pn**********************@news.easynews.com>. ..
I'm trying to get a handle on the best way to handle setting up my listings
so that I display groups of about 25 records per page. I currently have a
page that returns over 1,000 names/addresses, which is obviously not very
efficient. Does anyone have any suggestions on the best way to approach
this, or recommendations on what pitfalls to avoid? I'm assuming that I need
to be able to count the total number of records that match the search
criteria, possibly at the top of the page before any HTML output, then find
some way to identify/track the first record, next record, etc...? I know I
should replace my existing query with something that limits it to about 25
records at a time, right?

Thanx in advance for any/all suggestions!
Wm

<snip useless code>


You don't need any javascript to do paging. You need to use the LIMIT
clause in your sql SELECT statement in order to return a different set
of records each time. Before you do the SELECT you need to count the
records that match so you can determine the last page number. Take a
look at http://www.tonymarston.net/php-mysql...jects.html#a4d
for examples of how I handle this in an abstract database class.

Tony Marston
http://www.tonymarston.net//
Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.