Mr Chris Posted September 14, 2010 Share Posted September 14, 2010 Hello All, I have two arrays. One called $number_array and one called $title_array. $number_array = (1,2,3,4); $title_array = ("Title One", "Title Two", "Title Three", "Title Four"); Now what I want to do is run through each of the arrays one by one each time I query my database, so for example the first time it would output the query and title as: //First time SELECT * FROM tbl WHERE something = 1 <optgroup label="Title One"> //Second time SELECT * FROM tbl WHERE something = 2 <optgroup label="Title Two"> //etc.. so here's my code: <? echo '<select id="class" class="selectbox" name="class">'; $number_array = (1,2,3,4); $title_array = ("Title One", "Title Two", "Title Three", "Title Four"); $result = mysql_query ('SELECT * FROM tbl WHERE something = ".$number_array."') or die ('Error: '.mysql_error ()); echo '<optgroup label="".$title_array."">'; while ($row = mysql_fetch_array($result)) { echo '<option value="'.$row['id'].'" class="'.$row['name'].'">'.strtoupper($row['name']).'</option>'; } echo '</optgroup>'; echo ' </select>'; ?> Anyone please help? Link to comment https://forums.phpfreaks.com/topic/213369-looping-through-arrays/ Share on other sites More sharing options...
Mr Chris Posted September 14, 2010 Author Share Posted September 14, 2010 Worked it out using foreach and keys. Link to comment https://forums.phpfreaks.com/topic/213369-looping-through-arrays/#findComment-1110931 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.