I have two arrays both are coming from my SQL server
Example:
Array 1 (45, 46, 47, 48)
Array 2 (46, 47)
My code is as follows:
<select>
<?
while($array1 = $t->fetch_object()) /*Get from DB*/ {
foreach($array2 as $a2){
?>
<option <?=$array1 == $a2 ? 'value="'.$array1'" select="selected"' : 'value="'.$array1.'"'?>><?=$array1?><option>
<? } }?>
</select>
This will produce itself multiple times as it loops array2 twice. I for some reason can’t figure out how to run this properly without the multiple options. (Maybe I have been working all day) But any help will definitely be appreciated.
EDIT: so instead of the output being:
45
46 selected
47 selected
48
45 selected
46 selected
47
48
It be:
45
46 selected
47 selected
48
The above loops through twice due to the foreach and I’m not sure how to have it just loop through once. Hmm maybe if I have $i = 1 and it stop at the next count.
To clarify I am using this http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/ dropdown menu.
I might don’t understand well your question, but what I see from the code. You are trying to make default selection from array2. My way to do this would be :
The problem with this. You may have more than 1 “default” option (selected).
Hope this help.
antoine
(also I am a little rusty in php, not sure about “$array1 = $t->fetch_object()” part.)