MySQL Forums
Forum List  »  PHP

Re: Returing multiple rows based on 2 criteria
Posted by: Barry Galbraith
Date: December 10, 2012 03:08PM

It looks like this is the piece of code you need to get the items for a particular order

// Retrieve Order Items
$sql = mysql_query("SELECT * FROM `order_line` WHERE `orderID` = ".$row['orderID']);

$sql then contains a result object (if there are any data found) or false (if no data)
You then need to retrieve all the rows, where each row contains an array of the all the fields in the row (because you did SELECT *)
You get the rows one at a time by repeatedly calling mysql_fetch_array() until it returns false.

while ($orderItems = mysql_fetch_array($sql)){
	// $orderItems[0] now contains the first field of a row
	// $orderItems[1] now contains the second field of a row. I guess this is the text you want.
	//  so on and so on 
	// This is where you could do something with a returned field of a row
	// like add it to your output
	$output[] = $orderItems[1];
	}

the closing '}' now makes the "while" retrieve the next row
the "while" will terminate when there are no more rows

Good luck,
Barry.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.