Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我遇到了以下问题:
我有这个查询: SELECT firstName FROM users WHERE id = '$id'
SELECT firstName FROM users WHERE id = '$id'
这个查询很完美。但是,我想用 php 变量“$a”替换“firstName”。但是当执行这样的查询时,会返回字符串'firstName'。我该如何解决这个问题?
先感谢您。
$sql = 'SELECT `' . $a . '` FROM Users WHERE id = "' . $id . '"; ---------------^----------^ these are the characters you need
你会想要类似的东西
$sql = "Select ".$a." from users where id = '".$id."';