Showing Results Of A Query Through Php Script

Discussion in 'PHP' started by progfrog, Dec 9, 2008.

  1. #1
    hI!

    I do not know what is wrong with this code- because i don't get the results on screen as i wrote in the code:


    
    $rt=mysql_query("SELECT name FROM students"); 
    if(!$rt)
    echo "ERROR: error occured in MySQL query.";  // if any error is there that will be printed to the
    else
    {
    echo "connected successfully to query"; 
    while ($row=mysql_fetch_array($rt))
    {
    echo "name: {$row['name'] }".
    }
    }
    mysql_close($mysql_link); 
    ?>
    
    Need your help
    
    Progfrog
    
    
    
    Code (markup):
     
    progfrog, Dec 9, 2008 IP
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #2
    try like this
    $rt=mysql_query("SELECT name FROM students");
    if(!$rt)
    echo "ERROR: error occured in MySQL query."; // if any error is there that will be printed to the
    else
    {
    echo "connected successfully to query";
    while ($row=mysql_fetch_array($rt))
    {
    echo "name: {$row['name'] }";
    }
    }
    mysql_close($mysql_link);
    ?>
     
    crivion, Dec 9, 2008 IP
  3. kapinder

    kapinder Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Change the below code
    echo "name: {$row['name'] }".

    to
    echo "name: {$row['name'] }";
     
    kapinder, Dec 9, 2008 IP
  4. octalsystems

    octalsystems Well-Known Member

    Messages:
    352
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    135
    Digital Goods:
    1
    #4
    change these lines and hopefully it ill work

    $rt=mysql_query("SELECT name FROM students"); => $rt=mysql_query("SELECT `name` FROM students");
    echo "name: {$row['name'] }"; => echo "name: {$row[name] }";
     
    octalsystems, Dec 9, 2008 IP