SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot CDitty's Avatar
    Join Date
    Feb 2000
    Location
    Memphis Tn
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Returning an array from a function....

    I am trying to return an array from a function, but I am only getting 1 result. I know this has to be really simple, but I can't seem to figure it out. Can anyone offer any help?

    There are 561 results in the function, but I only get 1 from outside the function.

    Code:
    function selectMeter(){
    	$sql = mysql_query("select gmtr_id, gmtr_name from account_gmtr_t") or die(mysql_error());
    	
    	while($row = mysql_fetch_array($sql)){
    		$meterids[id] = $row[0];
    		$meterids[name] = $row[1];
    	}
    	
    	
    	echo mysql_num_rows($sql) . "<br>";
    	
    	return $meterids;
    }
    Chris

  2. #2
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do this:

    PHP Code:
    while ( $row = @ mysql_fetch_array $sqlMYSQL_ASSOC ) ) {

        
    $meterids[] = $row;


    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  3. #3
    SitePoint Zealot CDitty's Avatar
    Join Date
    Feb 2000
    Location
    Memphis Tn
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. Worked like a charm.

    Chris

  4. #4
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your welcome

    Sean
    Last edited by seanf; May 18, 2003 at 10:36.
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature


Bookmarks

Posting Permissions

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