garethhall Posted June 30, 2009 Share Posted June 30, 2009 Hello does anyone here know why my foreach loop is not going through all the photos? <?php $clientID = checkVars($_SESSION['clientID']); mysql_select_db($database_admin , $admin); //==============Select options=================== $SQL_options = "SELECT * FROM options WHERE optionStatus = 'on'"; $rs_options = mysql_query($SQL_options, $admin); //=======================Create Invoice number and select========================== $SQL_mkInv = "INSERT INTO invoice (invoiceID, invoiceDate, clientId, invoiceState) VALUES ('', CURDATE(), $clientID, '2')"; //if(mysql_query($SQL_mkInv,$admin)){ // $invID = mysql_insert_id(); // This is the invoice number //} // Select photos from Basket $SQLBasket = "SELECT * FROM basket WHERE clientId = $clientID"; $rsBasket = mysql_query($SQLBasket, $admin); while($rwBasket = mysql_fetch_assoc($rsBasket)){ // Insert Date into invoice details table $phID = $rwBasket['photoId']; //////////echo "Loop 1<b> ".$phID."</b>"; //############################################################ // If I echo the $phID here i get the all the selected photos from the basket //############################################################ // Set array to hold options Data from DB Using an array as I have to loop though the DB mutiple times $print_options = array(); while($rw_options = mysql_fetch_assoc($rs_options)){ $print_options[] = $rw_options ; } foreach($print_options as $options){ $theOption = $options['optionID']; $postSTR = $phID."qty-".$options['optionID']."opt"; echo $postSTR."<br>"; //############################################################ // If I echo $postSTR I only get the first photo in the loop WHY //############################################################ // if($_POST[$postSTR] >= 1){ $theQTY = $_POST[$postSTR];// the qty of set photo // echo "photoID ".$phID."--QTY".$theQTY."<br>";// checking result // $SQL_insertDetails = "INSERT INTO invoiceDetail (clientId, albumId, photoId, optionId, invoiceId, quantity, dState) VALUES ($clientID, '1','$phID', '$theOption', '$invID', '$theQTY', 'CREATE CONDITION FOR PRINT OR DIGITAL' )"; /* if(mysql_query($SQL_insertDetails, $admin)){ // Update basket IE remove value that hase been added to the invoice details $SQL_delBasket = "DELETE FROM basket WHERE clientId = $clientID AND photoId = '$phID'"; mysql_query($SQL_delBasket,$admin); } */ // } } } Link to comment https://forums.phpfreaks.com/topic/164176-solved-loop-not-giving-me-the-result-i-want/ Share on other sites More sharing options...
nadeemshafi9 Posted June 30, 2009 Share Posted June 30, 2009 try this and post the results while($rw_options = mysql_fetch_array($rs_options)){ $print_options[] = $rw_options ; } print_r($print_options); die(); Link to comment https://forums.phpfreaks.com/topic/164176-solved-loop-not-giving-me-the-result-i-want/#findComment-866037 Share on other sites More sharing options...
garethhall Posted June 30, 2009 Author Share Posted June 30, 2009 I have bad the code like that before but the result was the same. Link to comment https://forums.phpfreaks.com/topic/164176-solved-loop-not-giving-me-the-result-i-want/#findComment-866061 Share on other sites More sharing options...
sasa Posted June 30, 2009 Share Posted June 30, 2009 move this part $print_options = array(); while($rw_options = mysql_fetch_assoc($rs_options)){ $print_options[] = $rw_options ; } before 1st while loop Link to comment https://forums.phpfreaks.com/topic/164176-solved-loop-not-giving-me-the-result-i-want/#findComment-866143 Share on other sites More sharing options...
nadeemshafi9 Posted June 30, 2009 Share Posted June 30, 2009 move this part $print_options = array(); while($rw_options = mysql_fetch_assoc($rs_options)){ $print_options[] = $rw_options ; } before 1st while loop i think i rember somthing about while loops with to array mysql embeded within one another has issues ? ??? Link to comment https://forums.phpfreaks.com/topic/164176-solved-loop-not-giving-me-the-result-i-want/#findComment-866229 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.