jackiejackie Posted August 7, 2011 Share Posted August 7, 2011 Instead of having 3 queries to a mysql table to fill 3 different select boxes, I'm wondering if it would be better, time-wise, to have one query and sort the data into 3 different select boxes. So, with the results from the query, test them such as "if certain_field="A" load into Select Box 1 else if certain_field = "B" load into Select Box 2 else load into Select Box 3".. I'm thinking I might need to sort them into 3 different arrays first (?) ..... but do not know how to do this - Thank you - Quote Link to comment https://forums.phpfreaks.com/topic/244161-sort-results-from-mysql-query-into-3-different-select-boxes/ Share on other sites More sharing options...
MasterACE14 Posted August 8, 2011 Share Posted August 8, 2011 do you have any code to show for this? You will probably need the 3 queries, however when you 'fetch' them they will be put into arrays, you don't need to put them into arrays again. Quote Link to comment https://forums.phpfreaks.com/topic/244161-sort-results-from-mysql-query-into-3-different-select-boxes/#findComment-1253926 Share on other sites More sharing options...
jcbones Posted August 8, 2011 Share Posted August 8, 2011 while($row = mysql_fetch_assoc($result)) { $storage[$row['certain_field']][] = $row['id']; } foreach($storage as $field => $arr) { echo '<select name="' . $field . '">'; foreach($arr as $id) { echo '<option>' . $id . '</option>'; } echo '</select>'; } Something like that, you will have to play with it though. Quote Link to comment https://forums.phpfreaks.com/topic/244161-sort-results-from-mysql-query-into-3-different-select-boxes/#findComment-1253935 Share on other sites More sharing options...
jackiejackie Posted August 8, 2011 Author Share Posted August 8, 2011 Thank you both - I thought 3 queries would be a huge waste of time but running through the results and sorting into new arrays might be too - thank you Quote Link to comment https://forums.phpfreaks.com/topic/244161-sort-results-from-mysql-query-into-3-different-select-boxes/#findComment-1254204 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.