hyster Posted May 15, 2013 Share Posted May 15, 2013 im trying to get a MySQL result to be stored in a variable(array) so I can use the array later. ive never had to do this before and the search's ive done don't seem to do what I need. the end result im after is a members list. the array im tryin to build will be compared to another query and the other query will have the names removed so I don't echo the same name twice. my code works with a manual array but I want to build the array from a different table hence this query I carnt get working. $sql5 = "SELECT * FROM officer order by 'name' asc"; $result5=mysql_query($sql5) or die ( mysql_error () ); while($row5 = mysql_fetch_array( $result5 )) { $test = array($row5['name']); } // //the end result I want from the above query so I can use it later $test = array("name1", "name2", "name3", "name4", "name5", "name6"); Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 15, 2013 Share Posted May 15, 2013 Do you have error checking turned on? I'd be surprised if line 6 doesn't throw a warning or something. Anyway - line 6 is trying to typecast a simple variable as an array and assign it (as an array?) to a var called $test. But then the next iteration is going to do the exact same thing with the next row, so basically you'll end up with the last row's value in the var $test. Perhaps you should turn on error checking when you are developing. And as an answer to your woes, try doing this: $test[] = $row5['name']; This will give you an array have the contents of each 'name' field in it. Quote Link to comment Share on other sites More sharing options...
Solution hyster Posted May 15, 2013 Author Solution Share Posted May 15, 2013 thx ginerjm. that was enough for me to solve it 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.