php - "Array" is displaying in dropdown instead of values fetched from database -


code snippet html_form_class

<?php $frmstr = $frm->addselectlist(                       'city',                       $city,                       true,                       '',                       '--- select city ---',                       array(                           'class' => 'dropdown-style5',                           'id' => 'city'));  echo $frmstr; ?> 

code snippet seachcar.php

   $city = $db->select('city','city_name'); foreach($city $row) {  $row; } 

"array" displaying in dropdown instead of values fetched database please advice!

function addselectlist($name, $option_list, $bval = true, $selected_value = null,             $header = null, $attr_ar = array() ) {         $str = "<select name=\"$name\"";         if ($attr_ar) {             $str .= $this->addattributes( $attr_ar );         }         $str .= ">\n";         if ( isset($header) ) {             $str .= "  <option value=\"\">$header</option>\n";         }         foreach ( $option_list $val => $text ) {             $str .= $bval? "  <option value=\"$val\"": "  <option";             if ( isset($selected_value) && ( $selected_value === $val || $selected_value === $text) ) {                 $str .= $this->xhtml? ' selected="selected"': ' selected';             }             $str .= ">$text</option>\n";         }         $str .= "</select>";         return $str;     } 

html output of addselectlist function is

  <select name="city" class="dropdown-style5" id="city">   <option value="">--- select city ---</option>   <option value="0">array</option>   <option value="1">array</option>   <option value="2">array</option>   <option value="3">array</option> 

you need rebuild array of cities:

$city = $db->select('city','city_name'); $city_rebuild = array(); foreach($city $row) {     $city_rebuild[] = $row['city_name']; } $city = $city_rebuild; 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -