SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    I posted a few days ago and was refered to another post. I tried to figure it out but I seem to learn a little better when I can actually see what has been done.
    What I want to do is show only 10 results per page, and have the user clicknext to view the next 10 and so on. I am so lost can somebody please help.
    This is my code I am trying to add the next to.

    <html>
    <head>
    <style type="text/css">
    body {font-family:verdana,arial; font-size:10pt}
    TD {font-family:verdana,arial; font-size:10pt}
    #header {color:white; font-weight:bold; font-family:verdana,arial}
    A {color:navy; text-decoration:underline}
    A:hover {color:red}
    A:visit {color:navy}
    </style>
    </head>

    <body>
    <table border=0 bgcolor=black width=650 cellpadding=0 cellspacing=0>
    <tr><td>
    <table border=0 cellpadding=2 cellspacing=1 width=100%>
    <tr bgcolor=navy>
    <td align=middle id="header">NAME</td>
    <td align=middle id="header">ID</td>
    <td align=middle id="header">PRICE</td>
    <td align=middle id="header">PEOPLE</td>
    <td align=middle id="header">GAMES</td>
    <td align=middle id="header">DESCRIPTION</td>
    <td align=middle id="header">RATING</td>

    </tr>
    <?php
    require("mydb.inc");
    mysql_connect(localhost,$user,$password);

    $database="*********";
    @mysql_select_db("$database") or die( "Unable to select database");

    /*Search database */
    $table="things";

    $query="select * from $table group by id";

    $result=mysql_query($query);

    mysql_close();

    /*Display Results*/

    $num=mysql_numrows($result);

    $i=0;
    while ($i < $num) {


    $id=mysql_result($result,$i,"id");
    $name=mysql_result($result,$i,"name");
    $url=mysql_result($result,$i,"url");
    $price=mysql_result($result,$i,"price");
    $storage=mysql_result($result,$i,"people");
    $pop3=mysql_result($result,$i,"games");
    $description=mysql_result($result,$i,"description");
    $rating=mysql_result($result,$i,"rating");


    print ($i % 2) ? "<tr bgcolor=\"D7DEFF\">" : "<tr bgcolor=\"C2CCFF\">";

    echo "<td align=middle><A HREF=\"$url\" target=\"_blank\"><B>$name</B></A></td>";
    print "<td align=middle><b>$id</b></td><td align=middle><b>$price</b></td>";
    print "<td align=middle><b>$people</b></td><td align=middle><b>$games</b></td>";
    print "<td align=middle><b>$description</b></td><td align=middle><b>$rating</b></td>";


    ++$i;
    }


    ?>

    </table>
    </td></tr>
    </table>


    </body>
    </html>

  2. #2
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Are you getting any errors with that code?

    I do not believe you can call mysql_close(); and then call mysql_num_rows();

  3. #3
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    no errors

    The code works just fine, I get no errors.
    But thanks for replying.

  4. #4
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You may be able to accomplish what you want by using the mySQL LIMIT parameter. For example:

    SELECT * FROM foo LIMIT 10,10

    would return 10 rows starting at the 10th row. Handling which "page" of records that is returned could be accomplished by replacing one of the limit parameters with a value , something like:

    LIMIT 10, ($page * 10)


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
  •