Forum Moderators: coopster
I'm trying to work a series of functions like this:
function get_data($cnum,$invnum){
$query = 'SELECT * FROM sales WHERE invnum ='.$invnum.' AND relcid ='.$cnum;
$result = mysql_query($query);
$invoice = mysql_fetch_assoc($result);
$query = 'SELECT * FROM cdata WHERE cid ='.$cnum;
$result = mysql_query($query);
$customer = mysql_fetch_assoc($result);
$query = "SELECT * FROM ".$invoice['reltable']." WHERE item ='".$invoice['relitemno']."'";
$result = mysql_query($query);
$bought = mysql_fetch_assoc($result);
return $invoice;
return $customer;
return $bought;
}
and I want to use the RETURN arrays in another function like this:
function build_mail($invoice,$customer,$bought)
but it's not working! can someone please tell me why?
John
$data = function build_mail($invoice,$customer,$bought) Because of this, you normally only have one item returned, though it could be an array holding those three values.
$cnum=$_GET['cust'];
$invnum=$_GET['invoice'];
and the functions are called in order at the bottom of the same page:
get_data($cnum,$invnum);
build_mail($invoice,$customer,$bought);
customer_thanks($customer,$saddr,$bought,$invoice);
?>
perhaps my return statement should be:
return $invoice,$customer,$bought;
If called from within a function, the return() statement immediately ends execution of the current function, and returns its argument as the value of the function call.
Taken from the PHP Manual on Return [us4.php.net].
Look back at my first post. I think it's right.
$data=get_data($cnum,$invnum);
There is also a problem in that you are trying to return three arrays from the function, which is not easy to do unless you construct something like:
function get_data($cnum,$invnum){
$query = 'SELECT * FROM sales WHERE invnum ='.$invnum.' AND relcid ='.$cnum;
$result = mysql_query($query);
$data['invoice'] = mysql_fetch_assoc($result);
$query = 'SELECT * FROM cdata WHERE cid ='.$cnum;
$result = mysql_query($query);
$data['customer'] = mysql_fetch_assoc($result);
$query = "SELECT * FROM ".$invoice['reltable']." WHERE item ='".$invoice['relitemno']."'";
$result = mysql_query($query);
$data['bought'] = mysql_fetch_assoc($result);
return $data;
}
and then you can extract the data using the appropriate key.
I hope that begins to help...