$orderid WILL NOT contain all the rows. mysql_fetch_array() returns only one row each time it is called. Upon fetching last row, it returns NULL/FALSE/0. Therefore, as you fetch each row, you will then execute your second function to pull all the data for that particular order number. Finally, when executing mysql_query(), ALWAYS execute it in conjuction with die(mysql_error()) in order to get error messages concerning failures. Execute mysql_connect() and mysql_db_connect() only ONCE per script.
function get_live_orders() { $query = "select orderid from email where checked='no'"; $result = mysql_query($query) or die("Error: cannot select orderid<BR>$query<BR>".mysql_error()); while( $row = mysql_fetch_array($result)) { extract($row); $query2 = "SELECT * FROM orders WHERE orderid=\"$orderid\""; $result2 = mysql_query()) or die("Error: cannot fetch order<BR>$query2<BR>".mysql_error()); extract(mysql_fetch_array($result2)); } ----- Original Message ----- From: "Steve Jackson" <[EMAIL PROTECTED]> To: "PHP General" <[EMAIL PROTECTED]> Sent: Tuesday, November 05, 2002 8:50 AM Subject: [PHP] Help me learn! with an explanation of these two functions. Can someone run over these functions I have written to explain if my logic is correct. I'm still new to PHP and am trying to get my head round it! This first function is to collect a list of order numbers from my database where checked = no. Am I correct in assuming that the variable $orderid will be an array of results returned? How can I check this? function get_live_orders() { $conn = db_connect(); $query = "select orderid from email where checked='no'"; $result = @mysql_query($query); if(mysql_numrows($result)>0) $orderid = @mysql_fetch_array($result); return $orderid; } This second function is to take these order numbers and compare them to order numbers in a second table and return the result of that. So if order number 100001 is in the first array from the above function and there is a number 100001 in the second query result I want to take all the data in that row and return it. function get_order_details() { $orderid = get_live_orders(); $conn = db_connect(); $query = "select * from orders where orderid='$orderid'"; $result = @mysql_query($query); if (!$result) return false; $result = mysql_result($result, 0, "orderid"); return $result; } I haven't actually run this yet but I'd like someone to explain to me what these functions will do so I am not just copy pasting code and hoping to get it right eventually! Probably I have written this wrong anyway and would like help before I actually attempt to do what I am after. I'll look back on this tomorrow so any help will be greatly appreciated. Kind regards, Steve Jackson Web Developer Viola Systems Ltd. http://www.violasystems.com [EMAIL PROTECTED] Mobile +358 50 343 5159 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php