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'
このクエリは完璧に機能します。ただし、「firstName」を php 変数「$a」に置き換えたいと考えています。しかし、そのようなクエリを実行すると、文字列「firstName」が返されます。どうすればこれを解決できますか?
前もって感謝します。
$sql = 'SELECT `' . $a . '` FROM Users WHERE id = "' . $id . '"; ---------------^----------^ these are the characters you need
あなたは次のようなものが欲しいでしょう
$sql = "Select ".$a." from users Where id = '".$id."';