该死的对我的 MYSQL 查询的语法感到困惑。
这是正确的吗?在互联网上找不到类似的条目。
$query_game_string = '';
while($game = mysql_fetch_assoc($get_game_list)){
$query_game_string .= ' OR target = "' . $game['id'] . '" AND ancestors = "0"';
}
echo '' . $query_game_string . '';
//prints: OR target = "11" AND ancestors = "0" OR target = "12" AND ancestors = "0" OR target = "27" AND ancestors = "0" OR target = "29" AND ancestors = "0" OR target = "32" AND ancestors = "0"
$database->connect();
$comments = mysql_query(
'SELECT *
FROM ' . $database->db_prefix . 'comments
WHERE user_id = "' . $user->user_object["id"] . '"' .
$query_game_string . '
ORDER BY created DESC'
, $database->connection_handle);
$database->close();
所以实际的查询总共是:
'SELECT *
FROM ' . $database->db_prefix . 'comments
WHERE user_id = "' . $user->user_object["id"] . '"' .
'OR target = "11" AND ancestors = "0" OR target = "12" AND ancestors = "0" OR target = "27" AND ancestors = "0" OR target = "29" AND ancestors = "0" OR target = "32" AND ancestors = "0"' . '
ORDER BY created DESC'
语法好吗?