By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 916 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

select single row by id in php mysql

P: 1
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.
Nov 30 '11 #1
Share this Question
Share on Google+
2 Replies


100+
P: 155
Expand|Select|Wrap|Line Numbers
  1. $sql=mysql_query("select * from `yourtable` where id='theid'")or die(mysql_error());
  2. $row=mysql_fetch_assoc($sql);
  3. echo $row['name1'].$row['name2'].$row['name3'].$row['name4'];
  4.  
hope it helps
Dec 1 '11 #2

omerbutt
100+
P: 638
$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'];
you need to add limit 1 to ensure only 1 reccord is selected as there could be multiple rows against a single id
Expand|Select|Wrap|Line Numbers
  1. $sql=mysql_query("select * from `yourtable` where id='theid' LIMIT 1")or die(mysql_error());
  2.     $row=mysql_fetch_assoc($sql);
  3.     echo $row['name1'].$row['name2'].$row['name3'].$row['name4'];
  4.  
Dec 1 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.