select single row by id in php mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prohor s
    New Member
    • Nov 2011
    • 1

    select single row by id in php mysql

    Hi there, I am learning php mysql. Now I am trying to shwo a single row from a table by inserting id. That means i can read any row form table by inserting only id and that id contains other information like name , address will show with id. Please help....Thanks in advance.
  • canabatz
    New Member
    • Oct 2008
    • 155

    #2
    Code:
    $sql=mysql_query("select * from `yourtable` where id='theid'")or die(mysql_error());
    $row=mysql_fetch_assoc($sql);
    echo $row['name1'].$row['name2'].$row['name3'].$row['name4'];
    hope it helps

    Comment

    • omerbutt
      Contributor
      • Nov 2006
      • 638

      #3
      $sql=mysql_quer y("select * from `yourtable` where id='theid'")or die(mysql_error ());
      $row=mysql_fetc h_assoc($sql);
      echo $row['name1'].$row['name2'].$row['name3'].$row['name4'];
      you need to add limit 1 to ensure only 1 reccord is selected as there could be multiple rows against a single id
      Code:
      $sql=mysql_query("select * from `yourtable` where id='theid' LIMIT 1")or die(mysql_error());
          $row=mysql_fetch_assoc($sql);
          echo $row['name1'].$row['name2'].$row['name3'].$row['name4'];

      Comment

      Working...