quick PHP and MySQL selection question...

Discussion in 'PHP' started by MCJim, Aug 25, 2008.

  1. #1
    I would like to select all the rows from a table that share the same value in a certain field.

    Example:

    [B]username[/B]     [B]message[/B]
    bob          hello
    jim          howdy
    susan        hi
    jim          hey
    Code (markup):
    I know how to select one row:
    "SELECT message FROM users WHERE username = 'jim'"
    Code (markup):
    but I would like to select all rows where the username is 'jim' and echo them out. So in this example, it would display 'howdy' and 'hey'.

    Any help is appreciated as always, thanks.
     
    MCJim, Aug 25, 2008 IP
  2. Wrighty

    Wrighty Peon

    Messages:
    199
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?php
    $sql = mysql_query("SELECT message FROM users WHERE username = 'jim'");
    while($row = mysql_fetch_array($sql)){
    echo $row['message'];
    }
    ?>
    Code (php):
     
    Wrighty, Aug 25, 2008 IP
  3. MCJim

    MCJim Peon

    Messages:
    163
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks, it worked fine!
     
    MCJim, Aug 25, 2008 IP