我使用这个代码,所以我可以更新数据库中的记录:
$query = mysql_query("UPDATE article
SET com_count = ". $comments_count
WHERE article_id = .$art_id ");
我的问题是:如何在MySQL UPDATE语句中使用变量
$query = mysql_query("UPDATE article set com_count = $comments_count WHERE article_id = $art_id");
你把引号和concats弄乱了。
您可以像前面的例子一样使用内联变量,或者像下面这样连接它们:
$query = mysql_query("UPDATE article set com_count = " . $comments_count . " WHERE article_id = " . $art_id);
你把" .
模式搞砸了。
$query = mysql_query("UPDATE article set com_count = ". $comments_count . " WHERE article_id = " . $art_id . ");
当在MySQL UPDATE语句中使用变量时使用撇号:
$query = mysql_query("UPDATE article
SET com_count = '$comments_count'
WHERE article_id = '$art_id'");
注意空格和撇号