galvin Posted May 19, 2009 Share Posted May 19, 2009 I have this simple mysql query bringing back just TWO items (1986 and 1990)... $sql = "SELECT item FROM quizitems WHERE quizid = $quizid"; $result = mysql_query($sql, $connection); if (!$result) { die("Database query failed: " . mysql_error()); } else { while ($singlearray = mysql_fetch_array($result, MYSQL_NUM)) { print_r($singlearray); } But that gives the following output, i.e. TWO, SEPARATE one element arrays... Array ( [0] => 1986 ) Array ( [0] => 1990 ) Instead, I just want ONE single array with TWO elements in it, which would look something like this... Array ( [0] => 1986, [1] => 1990 ) How do I do that? This has to be easy but I'm going nuts trying to figure it out. ??? Quote Link to comment https://forums.phpfreaks.com/topic/158675-solved-turning-mysql-results-into-a-single-array-with-multple-elements/ Share on other sites More sharing options...
.josh Posted May 19, 2009 Share Posted May 19, 2009 while ($singlearray = mysql_fetch_array($result, MYSQL_NUM)) { $array[] = $singlearray[0]; } print_r($array); Quote Link to comment https://forums.phpfreaks.com/topic/158675-solved-turning-mysql-results-into-a-single-array-with-multple-elements/#findComment-836869 Share on other sites More sharing options...
galvin Posted May 19, 2009 Author Share Posted May 19, 2009 Ahhh, once I see it, it makes perfect sense. Very frustrating not being able to come up with this stuff myself yet. Anyway, thank you so much! Quote Link to comment https://forums.phpfreaks.com/topic/158675-solved-turning-mysql-results-into-a-single-array-with-multple-elements/#findComment-836870 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.