Question

I'm trying to create a dynamic list that will show item of my "city" table. But my code shows a drop down menu instead of a list. Can anybody help me by telling how to construct a dynamic list from it. I've tried goggling it but didn't find helpful resources.

A part of my code:

          <?php echo form_open('frontpage/index');?>
          <p><select name ='city_city_id'>
          <?php echo form_error('city_city_id'); ?>

<?php
$getType = mysql_query("SELECT city_id, cityname FROM city ORDER BY city_id");
while($type = mysql_fetch_object($getType)){
    echo "<option value=\"{$type->city_id}\">{$type->cityname} </option>",set_value('city_city_id');
}


?> 
    <p><input type="submit" value="submit" /></p>

       <?php echo form_close();?>   
Was it helpful?

Solution

<?php echo form_open('frontpage/index');?>
<p>
<?php echo form_error('city_city_id'); ?>
<select name="city_city_id" multiple="multiple">

<?php
$getType = mysql_query("SELECT city_id, cityname FROM city ORDER BY city_id");
while($type = mysql_fetch_object($getType)){
    echo "<option value=\"{$type->city_id}\">{$type->cityname} </option>",set_value('city_city_id');
}
?>
</select>
</p> 
<p><input type="submit" value="submit" /></p>

<?php echo form_close();?>   

OTHER TIPS

You need to put multiple="multiple" into your select tag.

For example

<select multiple="multiple">
  <option>Volvo</option>
  <option>Saab</option>
  <option>Mercedes</option>
  <option>Audi</option>
</select>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top