小编Spy*_*007的帖子

如何针对数组运行foreach并将其包含在SQL查询中?

所以我希望能够从数组中获取值并在SQL查询中使用它,并从这些行中获取信息.我目前的代码是这样的:

$config['exclude_devices'] = array('1','5');
Run Code Online (Sandbox Code Playgroud)

 

$exclude = $config['exclude_devices'];
foreach ($exclude as $excluded) {
    $deviceinformation = mysqli_query($db, "SELECT * FROM `devices` WHERE `device_id` NOT IN(" . $excluded . ")");
}
while ($row = mysqli_fetch_assoc($deviceinformation)) {
    // do stuff here
    // write to a variable for use in a table
}
Run Code Online (Sandbox Code Playgroud)

但是,这给出了设备1,2,3,4的输出.

如果我移动foreach包括while,它产生2,3,4,5,1,2,3,4:

$exclude = $config['exclude_devices'];
foreach ($exclude as $excluded) {
    $deviceinformation = mysqli_query($db, "SELECT * FROM `devices` WHERE `device_id` NOT IN(" . $excluded . ")");
    while ($row …
Run Code Online (Sandbox Code Playgroud)

php mysql

3
推荐指数
1
解决办法
98
查看次数

悬停时将图像更改为文本

如何在悬停时将图像更改为文本,并在鼠标离开时使用 HTML、CSS 和 JavaScript 再次返回?如果这有什么不同,我目前正在使用HTML5UP 的空中主题

html css

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

css ×1

html ×1

mysql ×1

php ×1