我试图获取一些行,提供$ admin_ID中的用户ID不存在。
$admin_ID = "1, 32, 34";
foreach($con->query('SELECT user_agent FROM wp_access_log WHERE user_id NOT IN ($admin_ID)') as $row2) {
$user_agent2 = $row2['user_agent'];
$browser2 = new BrowserDetection();
$browser2->setUserAgent($user_agent2);
$browserName2 = $browser2->getPlatform(); //string
$browserNameString2[] = $browserName2;
}
$string = var_export(array_count_values($browserNameString2), true);
echo "<table id='datatable-buttons' class='table table-striped table-bordered dt-responsive' cellspacing='0' width='100%'>";
echo "<tr><td><b>Browser</b></td><td><b>Visits</b></td></tr>";
$string = str_replace("array (","",$string);
$string = str_replace("' => ","</td><td>",$string);
$string = str_replace(",","</td></tr>",$string);
$string = str_replace(")","",$string);
$string = str_replace("'","<tr><td>",$string);
$string = $string . "</table>";
echo $string;
我收到以下错误:
警告:第543行的C:\ xampp \ htdocs \ account-stats.php中为foreach()提供的参数无效
注意:未定义的变量:第553行的C:\ xampp \ htdocs \ account-stats.php中的browserNameString2
警告:array_count_values()期望参数1为数组,在第553行的C:\ xampp \ htdocs \ account-stats.php中给出null NULL
如果我删除了代码:
WHERE user_id NOT IN ($admin_ID)
然后代码运行正常并加载数据库中的所有记录。
我可以得到一个关于我在这里做错了什么的指针吗?
答案 0 :(得分:3)
PHP
变量插值才有效。因此PHP
不会替换{sigle引号之间的$admin_ID
查询中的SQL
值,并且您的查询不正确。将查询放在双引号中:
"SELECT user_agent FROM wp_access_log WHERE user_id NOT IN ($admin_ID)"