html - Grab Selected Data using Select Box with PHP accessing a MySql database -
how grab selected data select box database? i've succeeded in doing radio button, when grabing select box stuck.
the theory is, if data in database saved 2007-2009 value in th_arsip
field, show again selected data (2007-2009) , show options when want update data update form.
here's code:
<?php require "config.php"; $id_arsip = mysqli_real_escape_string($conn,$_get['id_arsip']); $sql = "select * arsip id_arsip = '$id_arsip' "; $result = mysqli_query($conn, $sql); $data = mysqli_fetch_array($result); ?> <div class="col-xs-4"><label>year</label> <select name="th_arsip" id="th_arsip" class="form-control" required> <?php echo "<option value='2004-2006' ".($data['th_arsip'] == "2004-2006"?'checked':'')."> 2004-2006 </option> ". "<option value='2007-2009' ".($data['th_arsip'] == "2007-2009"?'checked':'')."> 2007-2009 </option> ". "<option value='2010-2012' ".($data['th_arsip'] == "2010-2012"?'checked':'')."> 2010-2012 </option> ". "<option value='2013-2015' ".($data['th_arsip'] == "2013-2015"?'checked':'')."> 2013-2015 </option> ". "<option value='2016-2018' ".($data['th_arsip'] == "2016-2018"?'checked':'')."> 2016-2018 </option> ". "<option value='2019-2021' ".($data['th_arsip'] == "2019-2021"?'checked':'')."> 2019-2021 </option> "; ?> </select> </div>
any appreciated. thanks
<select>
elements work off keyword selected
indicate highlighted value.
Comments
Post a Comment