mysql - PHP MySQLi prepared statement getting row, but not displaying data -
i'm trying fetch data using id database value. here code:
$query = "select id,uid,product,jpgid,saledatetime,quantity sales printed = ? , 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 images 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 information $print[$result_product][$result_jpgid]["quantity"] = $result_quantity; $print[$result_product][$result_jpgid]["location"] = $jpg; } } $stmt->close(); print_r($print); }
the echo $stmt_fetch->num_rows."<br />";
displays 1 each time loops, has found matching row. reason none of binded variables have value... here result displayed:
1 1 1 array ( [kr] => array ( [137] => array ( [quantity] => 1 [location] => ) [138] => array ( [quantity] => 1 [location] => ) ) [lr] => array ( [138] => array ( [quantity] => 1 [location] => ) ) )
managed fix it, here fixed code.
if(login_check($mysqli) == true) { //logged in $session_date = $_session['session_date']; $query = "select id,uid,product,jpgid,saledatetime,quantity sales printed = ? , 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 information $print[$result_product][$result_jpgid]["quantity"] = $result_quantity; } $stmt->close(); foreach ($print $key1 => $value1) { foreach ($print[$key1] $key => $value) { if ($stmt = $mysqli->prepare("select jpg,udate,imageset images 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"); }
Comments
Post a Comment