Jump to content

[SOLVED] Loop not giving me the result I want?


garethhall

Recommended Posts

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);
		}
		*/
//	}

}



}

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 ? ???

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.