View Full Version : Return Multiple Results

01-14-2008, 05:11 AM
Having a problem figuring out how to return more than 1 result from this code.

function GetBothUSERS($order)
global $ado;
$sql = "SELECT * FROM tbl_user tu
INNER JOIN tbl_user_vip tuv
ON tu.user_login_id=tuv.user_login_id
WHERE tuv.days > 0 AND
tuv.days DESC";
$resultvip = $ado->execute($sql);
$sql = "SELECT * FROM tbl_user WHERE user_status='A' ORDER BY $order DESC";
$result = $ado->execute($sql);
return ????? How do I return both results in order?

I want $resultvip first then $result. Thanks in advance!

01-14-2008, 05:20 AM
PHP like most languages cannot return multiple results from a function or method call. Therefore you have two options:

Return the result as an array or object to get the values you want
Add a parameter that is a reference to the original variable so that it can be changed within the function call.

So in your result:

return array($resultvip, $result);

In yours though, you could optimize it and bring it to a single query and return a single resultset instead. Check the sql forums for more specifics on how to do that.

01-14-2008, 05:28 AM
Ok got it thanks for the info..

01-14-2008, 05:29 AM
NP mate, let us know if you have any other troubles!