Add returned record values to select box in php
Stuck again... :)
I am returning close to 60 records from a search in mysql. I want to add these records to a select box.
When I am looping through the records, it adds a select box for each record. Not sure where I am going wrong. It does load the correct values, but one in each select box... -
<?php foreach($recordset as $record){ ?>
<select name="model" id="model" class="searchselectbox" onClick="toggleVisibility('pricelabel'); toggleVisibility('price');" onchange="this.form.submit();">
<?php echo '<option value="'.$record['type'].'">'.$record['type'].'</option>';?>
</select>
<?php
}
?>
I had the code like this below as well, still adding a select box for each record...
<?php foreach($recordset as $record){ ?>
<select name="model" id="model" class="searchselectbox" onClick="toggleVisibility('pricelabel'); toggleVisibility('price');" onchange="this.form.submit();">
<option value="<?php echo $record['type'];?>"><?php echo $record['type'];?></option>
</select>
<?php
}
?>
How can I get the option values loaded into only ONE select box? I have found plenty sample codes reflecting the above, mine just don't seem to want to work. :)
Related Article: ADD New Record Error
is a solved PHP discussion thread by tahirkhanafridi that has 6 replies and was last updated 1 year ago.
AndreRet
Industrious Poster
4,706 posts since Jan 2008
Reputation Points: 391
Solved Threads: 481
Skill Endorsements: 20
Hahahaha, how could I miss something that stupid.
Thanx Glider, all sorted now.
AndreRet
Industrious Poster
4,706 posts since Jan 2008
Reputation Points: 391
Solved Threads: 481
Skill Endorsements: 20
Question Answered as of 6 Months Ago by
GliderPilot a Little of topic if I may, still related though -
There is 3 select boxes, each one returns a different field from database i.e., in database - 2010 BMW 320i, record 2 2008 Aston Martin DB9 and so on.
What I do is to first get user to select a year, then submit form so I can return all vehicles with that year tied to them, then manufacturer (BMW, Aston Martin etc), then the type vehicle (320i, DB9 etc).
Problem is that the select goes back to default values once submitted/posted. How can I show the return values again. I still have the values available in php, i.e -
$vehicle_year
$vehicle_make
I'm just not sure how to "re-show" them in the select options?
AndreRet
Industrious Poster
4,706 posts since Jan 2008
Reputation Points: 391
Solved Threads: 481
Skill Endorsements: 20
Thank you, got it now!! lol.
AndreRet
Industrious Poster
4,706 posts since Jan 2008
Reputation Points: 391
Solved Threads: 481
Skill Endorsements: 20