2017-04-16 7 views
-1

助けてください、私はテーブルに配列(11,7,10)を挿入しています。エコーアレイからmysqlへ<option>値

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 \t name \t date \t re_doctor \t sex \t age \t no_ana \t name_pr 
 
11 \t aaaa \t 17/04/2017 \t \t Female \t \t 11,10,7 \t 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>

+0

まずmysql'廃止されました1 ''としてmysqli_extension'を使用する複数の属性を行う方法です!そしてあなたのtable_nameはあなたのコメントの中で** profile **と** users_table **と言っていたからです。 – Anonymous

+0

あなたが持っているのは、正規化が必要なデータベースです。 2番目のテーブルを作成します。ユーザー/医師のIDを追加し、「no_ana」と「name_pr」にそれぞれ1つの列を追加してから、それぞれの行を1つの行に転送します。そうすれば、ここに表示されているユーザーにリンクされている3つのID(IDは同じですが、「no_ana」と「name_pr」の内容が異なります)が表示されます。 – junkfoodjunkie

+0

テーブル名==>プロフィール –

答えて

0

が入ってくるフォームデータからループを実行し、データがmultiple option or a checkbox as an array

から11,7,10として入ってきたとしましょう:

は、今私は、このデータをエコーし​​たいですユーザーフォームの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> 
関連する問題