2017-04-16 4 views
-1

Bitte helfen Sie mir, ich bin das Array (11,7,10) in eine Tabelle einfügen.Echo-Array von Mysql in <option> Wert

Jetzt möchte ich diese Daten an echo:

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

allererst die 'mysqli_extension' als' mysql' verwenden ist veraltet ein! Und was ist Ihr Tabellenname, weil Sie ihn als ** Profil ** in der Abfrage und ** Benutzer_Tabelle ** in den Kommentaren erwähnt haben. – Anonymous

+0

Was Sie haben, ist eine Datenbank, die dringend normalisiert werden muss. Erstellen Sie eine zweite Tabelle, in der Sie die ID des Benutzers/Arztes hinzufügen, eine Spalte für "no_ana" und eine für "name_pr" und übertragen Sie dann jede einzelne in eine Zeile. Auf diese Weise haben Sie drei von ihnen mit dem Benutzer verbunden, den Sie hier zeigen - alle mit der gleichen ID, aber unterschiedlichen "no_ana" und "name_pr" Inhalt. – junkfoodjunkie

+0

Tabellenname ==> Profil –

Antwort

0

Hier können Sie Ihre Daten sagen kommen als 11,7,10 von einem multiple option or a checkbox as an array

Führen Sie eine Schleife aus den eingehenden Formulardaten von der array $no_ana bei dem Benutzerformular

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"); 
} 

Fügen Sie dieses Code-Snippet in Ihr Skript ein und testen Sie es.

Hier ist, wie Sie tun, um ein mehr Attribut

<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>