How to make id/name table into array?

From: Date: Tue, 21 Jan 2003 08:44:51 +0000
Subject: How to make id/name table into array?
Groups: php.general 
Request: Send a blank email to php-general+get-132360@lists.php.net to get a copy of this message
Is there a better way to do this in PHP? It seems that a single number (key) and single name (value) would lend itself perfectly to an (indexed or associative) array. I would think there is some PHP API call that I'm unaware of that will just take the whole result set and stuff it into an array for me no? If not, there should be. Perfect for things like ListBoxes, or table lookups so you don't have to hit the database constantly with joins et. al. $sql = "SELECT id, name FROM mytable ORDER BY id"; if ( !($result = mysql_query($sql,$link)) ) { echo "failed\n"; } while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) $myarray[$row['id']] = $row['name'];

« previous php.general (#132360) next »