我正在尝试使用其他数据库值中的ID获取一些数据。这是我的代码:
$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] =>
)
)
)
答案 0 :(得分:0)
管理修复它,这是我的固定代码。
if(login_check($mysqli) == true) {
//logged in
$session_date = $_SESSION['session_date'];
$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();
$stmt->bind_result($result_id,$result_uid,$result_product,$result_jpgID,$result_saledatetime,$result_quantity);
$count_rows = $stmt->num_rows;
while ($stmt->fetch()) {
//Create array's with information
$print[$result_product][$result_jpgID]["quantity"] = $result_quantity;
}
$stmt->close();
foreach ($print as $key1 => $value1) {
foreach ($print[$key1] as $key => $value) {
if ($stmt = $mysqli->prepare("SELECT jpg,udate,imageset FROM images WHERE id = ?")) {
$stmt->bind_param('i',$key);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($jpg,$udate,$imageset);
}
while ($stmt->fetch()) {
$print[$key1][$key]['location'] = $jpg;
}
}
}
print_r($print);
}
} else {
header("Location: index.php");
}