SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I have to pull 3 records from a database. Say the database is called data and, table is called users and field is called name.

    Thus:

    PHP Code:
    $sql "SELECT * FROM users LIMIT 3";
    $query mysql_query($sql); 
    Now, Heres the problem, I have to output them like this:

    Result 1
    <hr>
    Result 2
    <hr>
    Result 3

    How do i do this? I know you have to use a loop but how? You could say that the first two have a <hr> in them and the last doesn't. But how do you do this?

    Any help appreciated...

    Thanx

    Peter

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would have answered it on ICQ if you gave me the chance but here it is
    PHP Code:
    <?
    $sql 
    "SELECT * FROM users LIMIT 3";
    $query mysql_query($sql);
    $i 1;
    while(
    $row mysql_fetch_array($query)) {
        print 
    $row["name"]."<br>";
        print (
    $i 3) ? "<hr>" "";
    $i++;    
    }

    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LOL,

    I said nevermind on ICQ because i always ask you thing and thought you might get sick of me..


    Thanx so much!

    Peter
    Last edited by petesmc; Feb 18, 2001 at 19:01.

  4. #4
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, you can probably save yourself a line of code by using this - I'm pretty sure it will work. If not, Freddy will surely correct me post-haste.

    PHP Code:
    $query mysql_query("SELECT***FROM*users*LIMIT*3"); 

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Of course that would save a line of code, but sometime speople, myself included like to print our queries for debugging purposes, but that is the only time I do it.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •