How can I echo a this query?
$result = mysql_query("SELECT
car.id car_id,
FROM
car
WHERE car.id= $id ");
How can I echo the query above?开发者_开发百科
You're passing the query directly to the function. Store it in a variable if you want to echo it:
$query = "SELECT
car.id car_id,
FROM
car
WHERE car.id= $id ";
echo $query;
$result = mysql_query($query);
$query = "SELECT car.id,car_id FROM car WHERE car.id= $id ";
$result = mysql_query($query)
while ($car_details = mysql_fetch_array($result)){
echo "$car_details[id], $car_details[car_id]\n";
}
The above answer would echo the results of the query, if you simply want to echo the query string itself, store it as a string first, pass the string into the mysql_query function, and echo the string:
$sql = "SELECT car.id car_id, FROM car WHERE car.id= $id";
echo $sql;
$result = mysql_query($sql);
精彩评论