Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2007
    Posts
    78
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Return Multiple Results

    Having a problem figuring out how to return more than 1 result from this code.


    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 
    				tu.user_status='A' 
    				ORDER BY 
    				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!

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    PHP like most languages cannot return multiple results from a function or method call. Therefore you have two options:
    1. Return the result as an array or object to get the values you want
    2. 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:
    PHP Code:
        ...
        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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    mrnightowl (01-14-2008)

  • #3
    New Coder
    Join Date
    Jul 2007
    Posts
    78
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Ok got it thanks for the info..

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    NP mate, let us know if you have any other troubles!
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •