0
我试图从另一个数据库值中使用ID获取一些数据。这里是我的代码:PHP MySQLi准备语句获取行,但不显示数据
$query = "SELECT id,uid,product,jpgID,saledatetime,quantity
FROM sales
WHERE printed = ?
AND DATE_FORMAT(saledatetime, '%Y/%m/%d') = ?";
if ($stmt = $mysqli->prepare($query)) {
$printed = 0;
$stmt->bind_param("is",$printed,$session_date);
$stmt->execute();
$stmt->store_result();
//Get result
$stmt->bind_result($result_id,$result_uid,$result_product,$result_jpgID,$result_saledatetime,$result_quantity);
//Number of rows returned
$count_rows = $stmt->num_rows;
if ($stmt_fetch = $mysqli->prepare("SELECT jpg,udate,imageset FROM images WHERE id = ?")) {
//Fetch image information
while ($stmt->fetch()) {
$stmt_fetch->bind_param('i',$result_jpgID);
$stmt_fetch->execute();
$stmt_fetch->store_result();
$stmt_fetch->bind_result($jpg,$udate,$imageset);
echo $stmt_fetch->num_rows."<br />";
//Create array's with information
$print[$result_product][$result_jpgID]["quantity"] = $result_quantity;
$print[$result_product][$result_jpgID]["location"] = $jpg;
}
}
$stmt->close();
print_r($print);
}
的echo $stmt_fetch->num_rows."<br />";
显示1每次循环的时间,所以就找到了匹配的行。但对于没有绑定的变量的一些原因,没有任何价值......这是显示结果:
1
1
1
Array
(
[KR] => Array
(
[137] => Array
(
[quantity] => 1
[location] =>
)
[138] => Array
(
[quantity] => 1
[location] =>
)
)
[LR] => Array
(
[138] => Array
(
[quantity] => 1
[location] =>
)
)
)
并且您完全确定查看jpg,udate,imageset的第二个查询实际上与手动运行时提供的ID一起使用?即。在phpmyadmin或控制台?另外,对原始查询(我甚至不知道)进行连接并不容易,然后只是循环一个结果集,而不是将这2个结合起来使用 – Tularis
@Tularis,嗯它不运行如果我手动定义标识..:S这是我知道这样做的唯一途径,我将如何结合这些查询呢? –
还添加了第一个查询。 –