简体   繁体   中英

Get column value based on another columns value

Ok so if the title made any sense, I have an order form. I want the user to be able to search for their orders by the order number. Then I want to pull any info from that. So

ID | Name | Date
01 | John Smith | 12-13-11

If I query for an ID of 01, I want to be able to see the name John Smith. How can I do it? This doesn't give me what I want:

$name = "SELECT name FROM order WHERE id = '$prof'" . mysql_real_escape_string($prof) . "'";

should the name after SELECT be an *? Thanks!

Try this:

$query = "SELECT name FROM `order` WHERE id = '" . mysql_real_escape_string($prof) . "'";

Note that order is a reserved word in MySQL and should be surrounded by backticks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM