JasonHarper Posted May 22, 2010 Share Posted May 22, 2010 Hello! I'm having a brain block today! I'm retrieving two values from my database and want to write them as a pair (key/item) to an array. The issue I'm having is that if there is more than one set of records from my database, the array only contains the last pair (i.e., the array isn't holding every pair retrieved from the DB). //DEFINE ARRAY $portalAnnouncements = array(); //GET PORTAL SPECIFIC ANNOUNCEMENTS $result = mysql_query("SELECT announcementText, announcementClass FROM announcements WHERE announcementInUse='1'"); while($record = mysql_fetch_array($result)) { $portalAnnouncements[$record['announcementClass']] = $record["announcementText"]; } A print_r will always show only one key/item pair even if there are multiple items retrieved from the DB. I'm sure I'm missing something simple - thank you for any help!! Jason Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted May 22, 2010 Share Posted May 22, 2010 What does the print_r show exactly? Quote Link to comment Share on other sites More sharing options...
JasonHarper Posted May 23, 2010 Author Share Posted May 23, 2010 Sorry! I figured this out. The field I was using as the key was boolean (0/1) so when I had repeat values it was overwriting. I switched to use something else that's unique as the key. Thanks! Jason Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.