SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot pannick's Avatar
    Join Date
    Aug 2003
    Location
    Florida
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I am trying to limit my query results on my pages

    I am trying to limit my query results on my pages and have a next at the bottom of the page
    like this page http://www.outdoorsflorida.com/guideslist.php

    can some one please give advice?

    I am just learning this php stuff, love it but it can be frustrating.

    Here is a copy of my code

    <?php
    /*
    */
    ?>
    <?php include("header.php" ); ?>
    <?php include("confreg.inc" ); ?>
    <h4 align="center">Horse Farms And Stables </h4>
    <?php
    $connection = mysql_connect($host, $user, $password)
    or die ("Couldn't connect to server" );
    $db = mysql_select_db($database, $connection)
    or die ("Could't connect to database" );


    /* Select all categories from farms_stables */
    $query = "SELECT * FROM farms_stables ORDER BY name";
    $result = mysql_query($query)
    or die ("Couldn't execute query" );

    if ($result)

    /* Display results in a table */
    echo "<table align='center' cellspacing='1' border='0' cellpadding='2' width='60%'>";
    echo "<tr bgcolor='#FFFFFF'>
    <td><font size='2' color='3366CC'><b><u>Name</font></b></u></td>
    <td><font size='2' color='3366CC'><b><u>Address</font></b></u></td>
    <td><font size='2' color='3366CC'><b><u>City</font></b></u></td>
    <td><font size='2' color='3366CC'><b><u>State</font></b></u></td>
    <td><font size='2' color='3366CC'><b><u>Zip</font></b></u></td>
    <td><font size='2' color='3366CC'><b><u>Phone</font></b></u></td>
    </tr>";

    while ($r = mysql_fetch_array($result))
    { //Begin while
    $name = $r["name"];
    $address = $r["address"];
    $city = $r["city"];
    $state = $r["state"];
    $zip = $r["zip"];
    $phone = $r["phone"];
    echo "<tr>";
    if($r['url'])
    {
    $url = ( substr($r['url'], 0, 7) == 'http://' )
    ? $r['url']
    : 'http://'.$r['url'];
    echo "<td><b><font face='Arial' size='1'> <a href='$url' target='blank'>$name</font></b> </a>";
    }
    else
    {
    echo "<td><font face='Arial' size='1'>$name</font>";
    }
    echo "</td>
    <td><font face='Arial' size='1'>$address</font></td>
    <td><font face='Arial' size='1'>$city</font></td>
    <td><font face='Arial' size='1'>$state</font></td>
    <td><font face='Arial' size='1'>$zip</font></td>
    <td><font face='Arial' size='1'>$phone</font></td>
    </tr>
    <tr><td colspan=6 bgcolor=\"#ffffa0\"></td>
    </tr>";
    } // end while
    echo "</table>";




    ?>


    <!-- Footer Include Begin -->
    <p align=center>
    <TABLE cellpadding=0 cellspacing=0 border=0 width=678>
    <TR valign=top align=left>
    <TD width=676 height=15><?php include("footer.php" ); ?></TD>
    </TR>
    </TABLE>
    <p align=center>
    <TABLE cellpadding=0 cellspacing=0 border=0 width=678>
    <TR valign=top align=left>
    <TD width=676 height=15></TD>
    </TR>
    </TABLE>
    <!-- Footer Include End -->

  2. #2
    SitePoint Addict devil cat's Avatar
    Join Date
    Apr 2003
    Location
    Reno
    Posts
    344
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try:

    $query = "SELECT * FROM farms_stables ORDER BY name limit 0, 10";
    $result = mysql_query($query)

    That would display the first 10 results (the part: limit 0, 10). limit starts at the first number (0 being the first value in an array) and selects a number of records that you supply following that (in this case, 10).

    All you need to do to alter that per page (fingers crossed) is insert a variable into that 0 and increment it by whatever amount you choose so that when they click next they get the next set of records (in the case above, increment the value by 10).

  3. #3
    SitePoint Zealot pannick's Avatar
    Join Date
    Aug 2003
    Location
    Florida
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks how do I make the pages ont the bottom like the example that I posted?

    1,2,3 Next


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
  •