Jump to content

[ASK]how to display data from the database in the menu select?


fikiwan
 Share

Recommended Posts

you have too loop through the db result set and display each option tag in side select tag. have you tried anything yet?

Link to comment
Share on other sites

I hv problem fo display month I try lke this , but not running , wht wrong ??

<?php                    for ($i=1; $i<=12; $i++) {                   	                        $sele[$i]=="";                        if ($i == $bln)                        $sele[$i] == "SELECTED";                                           	                    }                	    echo("<option value=\"1\" $sele [1]>Januari");	    echo ("<option value=\"2\" $sele [2]>Februari");		 echo ("<option value=\"3\" $sele [3]>Maret");          echo ("<option value=\"4\" $sele [4]>April");           echo ("<option value=\"5\" $sele [5]>Mei");       	 echo ("<option value=\"6\" $sele [6]>Juni");             echo ("<option value=\"7\" $sele [7]>Juli");              echo ("<option value=\"8\" $sele [8]>Agustus");               echo ("<option value=\"9\" $sele [9]>September");           	 echo ("<option value=\"10\" $sele [10]>Oktober");                 echo ("<option value=\"11\" $sele [11]>November");                  echo ("<option value=\"12\" $sele [12]>Desember");        ?>	 <option/> </select>	  <select name="thn" id="thn">	    <option>Tahun</option>          <?php    $date = date('Y');                for($i=1985;$i<=$date;$i++) {                $sele = ($i==$thn)?"selected" : "";                        echo "<option value='$i' $sele>$i</option>";    }                ?>

how to display in menu select data month from db ..

Link to comment
Share on other sites

One problem is that I can't see the opening <select> tag for the first set of options. The second problem is that you shouldn't have a space between $sele and [1]. Because the [1] is now being interpretted as plain text, and $sele outputs "Array"

  • Like 1
Link to comment
Share on other sites

One problem is that I can't see the opening <select> tag for the first set of options. The second problem is that you shouldn't have a space between $sele and [1]. Because the [1] is now being interpretted as plain text, and $sele outputs "Array"
oh thanks I get it
 <select name="bln" id="bln">    	    <option value="0" selected="selected">Bulan</option>        <?php                    for ($i=1; $i<=12; $i++) {                        //$bl = ($i<10) ? "0$i" : $i;                        $sele [$i] = "";                        if ($i == $bln)                        $sele [$i] = "SELECTED";                                                //echo "<option value='$bl' $sele>$bl</option>";                        }                	    echo("<option value=\"1\" $sele[1]>Januari");	    echo ("<option value=\"2\" $sele[2]>Februari");		 echo ("<option value=\"3\" $sele[3]>Maret");          echo ("<option value=\"4\" $sele[4]>April");           echo ("<option value=\"5\" $sele[5]>Mei");       	 echo ("<option value=\"6\" $sele[6]>Juni");             echo ("<option value=\"7\" $sele[7]>Juli");              echo ("<option value=\"8\" $sele[8]>Agustus");               echo ("<option value=\"9\" $sele[9]>September");           	 echo ("<option value=\"10\" $sele[10]>Oktober");                 echo ("<option value=\"11\" $sele[11]>November");                  echo ("<option value=\"12\" $sele[12]>Desember");                 ?> <option/></select>

now its work .. ths :) now how to menu select other ex :

    <select name="genl" class="genl">	    <option>Jenis Kelamin</option>            if ()	    <option value="L">MEN</option>	    <option value="P">WOMEN</option>	  </select>

wht I should doing fo it . ??

Edited by fikiwan
Link to comment
Share on other sites

i am not sure what are you trying to do? if() is not doing anything and also probably out of the context of php. it seems like it is outside php block. to execute control structure like if-else it needs to be in php block.

Link to comment
Share on other sites

oh thank I get it :) my trying lke this

	  <select name="jenl" class="jenl">		<option selected="selected">Gender</option>			<?php												if ($hasil['jenkel'] == "L")echo"<option value=\"L\" selected>Meni</option>";			else echo"<option value=\"L\" >Men</option>";						 if ($hasil['jenkel'] == "P")echo"<option value=\"P\" selected>Women</option>";			else echo"<option value=\"P\" >Women</option>";		?>	  </select>

is there an easier way , ??makasih atas masukannya .... :)

Edited by fikiwan
Link to comment
Share on other sites

You're going to have to remove the selected="selected" from the first option. You can't have two options selected at the same time. You can include the "selected" part into the string.

$selected = ($hasil['jenkel'] == "L" ? 'selected="selected"' : '');echo "<option value=\"L\" {$selected}>Meni</option>";

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...