php - 带有 IN 子句的 PHP Prepared 语句不显示任何内容
问题描述
以下是我现在正在为比较网站测试的代码。但我无法使其与准备好的语句功能一起使用。如果我不使用准备好的语句方法,我的代码运行良好。表结构或使用foreach
可能看起来不是正确的方法,但对于其他一些功能是必需的。
<?php
$dbname="ty465yu67u76i7";
$dbpass="jf54tg5y65y66u";
$dbuser="4t5t5y6y65u67u";
$hostname="localhost";
// SETP TWO : connecting to the database
$mysqli = new mysqli($hostname, $dbuser, $dbpass, $dbname);
$pid1="202882";
$userIdArray = [202882,202883,202884];
// number of question marks
$questionMarksCount = count($userIdArray);
// create a array with question marks
$questionMarks = array_fill(0, $questionMarksCount, '?');
// join them with ,
$questionMarks = implode(',', $questionMarks);
// data types for bind param
$dataTypes = str_repeat('i', $questionMarksCount);
// SETP THREE : SQL query
$results = $mysqli->prepare("SELECT * FROM phonespecs WHERE pid IN('.$questionMarks.')");
$results -> bind_param($dataTypes, ...$userIdArray);
$results -> execute();
$results -> store_result();
?>
<div class="basic-information">
<h3>Basic Information </h3>
<table class="table">
<tbody>
<tr>
<td>Models</td>
<?php foreach ($results as $result){ ?>
<td> <strong><?php
if(!empty($result['name'])) {
$mobname=$result['name'];
} else{$mobname="Empty";}
echo $mobname; ?></strong> </td>
<?php } ?>
</tr>
<tr>
<td>Manufacturer</td>
<?php foreach ($results as $result){ ?>
<td> <strong><?php echo $result['brand']; ?></strong> </td>
<?php } ?>
</tr>
--以及更多表格数据--
解决方案
推荐阅读
- python - 使用正则表达式根据大写在字符串中添加空格?
- python - 我不明白内置功能(形状)
- django - 如何对 Django 说不要散列用户密码?
- php - 使用 PHP 将数据从 CSV 导入 MYSQL
- javascript - 从另一个按许多对象属性分组的对象返回数组
- qt - 为 Maya 插件创建没有调试 dll 的 VS 解决方案?
- python - 向用户询问他们的姓名和号码,显示他们的姓名该次数
- python - 从 xml 文件中提取列表或字典
- php - openid 连接以识别 php 中的服务器
- javascript - 如何在nodejs中将对象数组转换为字符串?