0
UPDATE post_categories 
SET posts_counter = ".$sql_totalbooknumber." 
WHERE  `name` =  'Posts'

使用上面的查询,我在“where子句”MYSQL错误中不断收到未知列“Posts”

这是我的 $sql_totalbooknumber

$sql_totalbooknumber = "SELECT SUM(posts_counter) FROM post_categoriesWHERE posts_counter> '0' AND category_id!= '355'";

4

2 回答 2

0

尝试这个 :

UPDATE post_categories 
SET posts_counter = '".$sql_totalbooknumber."' 
WHERE  `name` =  'Posts'

用单引号将值括起来。

于 2012-10-04T06:32:56.667 回答
0

因为变量$sql_totalbooknumber包含 SQL SELECT 查询,所以它必须放在括号中:

    $sql_totalbooknumber = "SELECT SUM(posts_counter) FROM post_categories WHERE posts_counter > '0' AND category_id != '355'";
    
    $sql_query = "UPDATE post_categories 
    SET posts_counter = (".$sql_totalbooknumber.") 
    WHERE  `name` =  'Posts'";

于 2020-12-08T22:07:16.587 回答