SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Happy Thanksgiving,

    What php code can I add to my scripts to limit only 5 or 6 records per page and then have Next, Back and 1 2 3 4 5 6 etc...on the bottom of the last record so that my visitors can find the next page of records?

    $result = mysql_query("SELECT Business_Name, Business_Description, Address_1, E_Mail, Web_Site, Business_Logo, Category, Subcategory, Visible, Phone_Number, Contact_Name, City, Zipcode, Neighborhood FROM Business
    Where Category = 'Bars & Clubs' and Visible = 'Y'
    ORDER BY Business_Name ASC");
    while ($row = mysql_fetch_array($result)) {

    printf('<tr bgcolor="8CA7C7"><td colspan=2><b>%s</b></td></tr>', $row["Business_Name"]);
    if ($row["Address_1"] != "")
    printf('<tr bgcolor="F3F3F3"><td>Address</td><td>%s</td></tr>', $row["Address_1"]);
    if ($row["City"] != "")
    printf('<tr bgcolor="F3F3F3"><td>City</td><td>%s</td></tr>', $row["City"]);
    if ($row["Neighborhood"] != "")
    printf('<tr bgcolor="F3F3F3"><td>Neighborhood</td><td>%s</td></tr>', $row["Neighborhood"]);
    if ($row["Phone_Number"] != "")
    printf('<tr bgcolor="F3F3F3"><td>Phone</td><td>%s</td></tr>', $row["Phone_Number"]);
    if ($row["E_Mail"] != "")
    printf('<tr bgcolor="F3F3F3"><td>E-Mail</td><td><A HREF="mailto:%s">%s</a></td></tr>', $row["E_Mail"], $row["E_Mail"]);
    if ($row["Web_Site"] != "")
    printf('<tr bgcolor="F3F3F3"><td>Web Site</td><td><A target="_blank" HREF="%s">%s</a></td></tr>', $row["Web_Site"], $row["Web_Site"]);

    if ($row["Business_Description"] != "")
    printf('<tr bgcolor="F3F3F3"><td colspan=2>%s</td></tr>', $row["Business_Description"]);
    printf('<tr bgcolor="F3F3F3"><td colspan=2>&nbsp;</td></tr>');
    }
    ?>

  2. #2
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know if you could do that using only MySQL, but the idea I used at http://www.123finder.com (looking up domains in the db and return by pages of 25 domains) is, make a for loop from the starting index (which should be passed into as a external var), then loop from $page -> $page*per_page+per_page

    For the page number, you could divide the array using count()

    Hope that gives you an idea!
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  3. #3
    SitePoint Zealot
    Join Date
    Nov 1999
    Location
    Manhattan!
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try something like this:

    <?

    $numResultsPrPage = 10;
    $count = 1;
    $start = 0;
    $stop = $numResultsPrPage;

    while($count) {
    $sql = "SELECT * FROM tableName LIMIT $start, $stop":
    $result = mysql_query($sql);
    $count = mysql_num_rows($result);

    // display your data ...

    $start += $count;
    $stop = $start + $numResultsPrPage;
    }

    Christian
    www.Christian.Reimer.com
    A personal website exploring the mental summersaults,
    odd occurrences and political powerplays in the land of me.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •