echo数组从mysql到<option>值

时间:2017-04-16 22:43:14

标签: php mysql

请帮助我,我将数组(11,7,10)插入表格。

现在我想回应这些数据:

click here to show table

like this structure iwant to make it
<select>
<option value="11">11- HbA1C</option>
<option value="7">10- O"Solivan Test</option>
<option value="10">7- Randam Blood Glucose</option>
</select>
/////////////////////////////////////
table==>
id	name	date	re_doctor	 sex	age 	no_ana	 name_pr
11	aaaa	17/04/2017	 	 Female	 	 11,10,7	 11- HbA1C,10- O"Solivan Test,7- Randam Blood Gluco.

////////////////////////////////////////////////
my code :-
<?
$qqq=$_GET['n'];
$sql = "SELECT * FROM `profile` where id ='$qqq'"; // select only the username field from the table "users_table"
$result = mysql_query($sql); // process the query

$username_array = array(); // start an array

while($row = mysql_fetch_array($result)){ // cycle through each record returned
  $array1[] = $row[6]; // get the username field and add to the array above with surrounding quotes
   // get the username field and add to the array above with surrounding quotes
  $array3[] = $row[7]; // get the username field and add to the array above with surrounding quotes
  }
?>
 <select> <option>
<?

foreach($array1 as $it=>$ss){
      foreach($array3 as $rr=>$vv){
         if ($it==$rr) {

         echo str_replace(',', '<option value="'.$ss.'">', $vv .'</option>');

         }


       }
}

 ?>
</select>

1 个答案:

答案 0 :(得分:0)

假设您的数据来自11,7,10

multiple option or a checkbox as an array

从用户表单中的array $no_ana传入的表单数据执行循环

foreach($no_ana as $key => $value){
 mysql_query("INSERT INTO table_name (id, name, date, 
                    re_doctor, sex, age, no_ana, etc)
              VALUES ($val1, $val2, $val3, $val4, 
                    $val5, $val6, $value, $etc");
}

将此代码段插入您的脚本并进行测试。

以下是执行多重属性的方法

 <select multiple name="name_pr[]">
  <option value="11">11- HbA1C</option>
  <option value="7">10- O"Solivan Test</option>
  <option value="10">7 - Ramdam Blood Glocose</option>
</select>