MySQLi Array in PHP sometimes coming up empty -
okay, i'm pretty @ end of rope trying discover issue here, because code works perfectly, , not, here is:
$allitems = array(); $allitemsquery = mysqli_query($conn,"select * cart_items crt_id='".$row['crt_id']."' , quantity>0"); while($itemsarray = mysqli_fetch_assoc($allitemsquery)){ array_push($allitems,$itemsarray['item_id']); } $allitemsnames = array(); foreach($allitems $key => $value){ $itemnames = mysqli_fetch_assoc(mysqli_query($conn,"select * items id='$value'")); array_push($allitemsnames, $itemnames['item_name']); } $allitemsfinal = array_combine($allitems,$allitemsnames); $itemslist = 'items:<br>'; foreach($allitemsfinal $key => $value){ $itemslist .='<a href="http://www.exampleurl.org/product.php?id='.$key.'">'.$value.'</a><br><br>'; }
the idea it's supposed of item id's user has in cart db , put array, i've established exists, grab of item names based on id, , put array, , combine 2 arrays key , value. output data arrays string.
this code works sometimes, , not. can give me idea why? i'd indebted forever.
i think should throw code away , use this:
$items = array(); $itemsquery = "select i.item_name, i.item_id items i.item_id in (select ci.item_id cart_items crt_id='".$row['crt_id']."' , quantity>0 )"); $allitemsquery = mysqli_query($conn, $itemsquery); while ($row = mysqli_fetch_assoc($allitemsquery)) $items[$row['item_id']] = $items[$row['item_name']];
Comments
Post a Comment