[英]Change is_numeric to check all values
I have this code: 我有以下代码:
foreach($feed['posts'][$i] as $key => $value)
{
$sql[] = (is_numeric($value)) ? "`$key` = $value" : "`$key` = '" . "'";
}
$sqlclause = implode(",",$sql);
This works fine, but it only fills in the values that have a number. 这可以正常工作,但是只填写具有数字的值。 If I take the is_numeric or change it into
($value)
or different variants of it, the query does completes, but no data is added to my MySQL database. 如果我使用is_numeric或将其更改为
($value)
或它的其他变体,则查询确实完成了,但是没有数据添加到我的MySQL数据库中。
Maybe because you're not adding a value if the value is not numeric: 可能是因为如果该值不是数字,则不添加值:
$sql[] = (is_numeric($value)) ? "`$key` = $value" : "`$key` = '" . $value . "'";
// ^^^^^^^^^^^^^^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.