1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Query to display data from database

Discussion in 'MySQL' started by Colbyt, Mar 15, 2007.

  1. #1
    I have a database with these fields and I want to view in my browser all the data for the record where the id=1 (or any other number I choose) what would I have to use as the query? I know the connection string. I just don't know what to do after I connect.

    TIA,
     
    Colbyt, Mar 15, 2007 IP
  2. linkstraffic

    linkstraffic Well-Known Member

    Messages:
    388
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    133
    #2
    if it's only a mysql tip you need, something simple like this is ok:

    
    SELECT * FROM yourtable WHERE id=yournumber;
    
    Code (markup):
     
    linkstraffic, Mar 16, 2007 IP
    Colbyt likes this.
  3. ThreeGuineaWatch

    ThreeGuineaWatch Well-Known Member

    Messages:
    1,489
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    140
    #3
    Is it the PHP code you are looking for? This will get you going on the right foot:

    <?
    
    $result = mysql_query("SELECT * FROM database_table WHERE id = 1 LIMIT 1");
    
    $row = mysql_fetch_array($result);
    
    foreach ($row as $fieldName => $field) {
       echo "Field: $fieldName, value: $field<br />\n";
       }
    
    ?>
    Code (markup):
    Cheers!
     
    ThreeGuineaWatch, Mar 16, 2007 IP
    Colbyt likes this.