比如:
$condition = "a_size";
$single_size = 30;
$sql_count = "select count(*) as count from foot_info WHERE '$condition' = '$single_size' ";
我这样运行,貌似什么也查询不到
但很奇怪,如果我用字符串连接成sql语句就可以正常查询,如下
$sql_count = "select count(*) as count from foot_info WHERE".$condition." = '$single_size' ";
/////////////////////////////////////
我又输出了上面两个sql语句的输出,分别是
select count(*) as count from foot_info WHERE Foot_Size = '30'//可运行
select count(*) as count from foot_info WHERE 'Foot_Size' = '30'//不可运行
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
把$condition的引号去掉就好。。
mysql的查询字段不需要加引号或者select count(*) as count from foot_info WHERE `Foot_Size` = '30'//可运行