Re: mysql_fetch_array to associative array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Andras Kende wrote:
Hello,

I use the following GetArray for returning an array from mysql results.

But having a hard time modifying it for returning a simple associative array

Like:

$conn->GetAssoc('SELECT id, name from manufacturers')

Array ( [2] => BMW [1] => MAZDA [9] => FORD )


		function GetArray($query) {
			$get = $this->Execute ( $query );
			

don't you need to check to make sure that $get is a valid resource???

			$result = array();

			while ( $row = mysql_fetch_array($get) ) {

All of this can be replace with this one line
				$result[] = $row;

			}
			mysql_free_result($get);
			
			return $result;
		}


		function GetAssoc($query) {
			$get = $this->Execute ( $query );
			

don't you need to check to make sure that $get is a valid resource???

			$result = array();

			while ( $row = mysql_fetch_assoc($get) ) {

				$result[] = $row;

			}
			mysql_free_result($get);
			
			return $result;
		}

I searched a lot but didn't find anything.

Thanks for any help :)

Andras



--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux