2013-01-05 46 views
0

我該如何啓動它?我知道我需要做一個mysql查詢,但如何轉換數據,在下拉列表中的選項。請記住,它是在一個表單內,從MySQL表發送結果。以MySQL數據爲表格提取下拉列表的數組

(EDIT)

我printf的,這就是我想裏面工作:

<?php ob_start(); 
include('/../../config.php'); 

if(isset($_POST['edit_id']) && !empty($_POST['edit_id'])) { 

$edit_id = mysql_real_escape_string($_POST['edit_id']); 
$result = mysql_query("SELECT username, password, nome, cidade, pais, base, isactive, admin, dov, checador, dinheiro, email, datanascimento, profissao, idivao, idvatsim, horas, rank FROM acars_users WHERE `id`='".$edit_id."'"); 
$resultdl = mysql_query("SELECT * FROM acars_hubs"); 

$data = mysql_fetch_array($result); 
$dl = mysql_fetch_array($resultdl); 


printf("<div align=\"center\"> 
<br><form method=\"post\" action=\"editar2.php\"> 
<p><font size=\"2\" face=\"Segoe UI, Arial, Helvetica, sans-serif\" align=\"center\">Modifique os campos que deseja para <strong>editar este membro.</font><br> 
<br> 

<table width=\"700\" border=\"0\" align=\"center\" > 
<tr> 
    <td>Base Operacional:</td> 
    <td><label for=\"hub\"></label> 
     <select name=\"hub\"> 
     <option>".$dl['name']."</option> 
     </select> 
    </td> 
    </td> 
</tr> 
</table></br></br> 
<input name=\"edit_id\" value=\"$edit_id\" type=\"hidden\"> 
<input type=\"image\" src=\"img/Editar.PNG\" width='85' height='30'></form> 
</form> 

</table> 
</div> 

"); 
while ($data = mysql_fetch_array($result)); 
while ($dl = mysql_fetch_array($resultdl)); 
ob_end_flush(); 
?> 

回答

0

我發現了這個問題。我的第一個$dl = mysql_fetch_array($resultdl, MYSQL_ASSOC);從表中拉出第一行。當我開始while循環mysql_fetch_array接下來一行。所以,解決方案是刪除第一個電話。這是最終的代碼:

<?php 
    include('../../../../../config.php'); 

    if(isset($_POST['edit_id']) && !empty($_POST['edit_id'])) { 

    $edit_id = mysql_real_escape_string($_POST['edit_id']); 

    $result = mysql_query("SELECT * FROM acars_users WHERE `id`='".$edit_id."'"); 
    $data = mysql_fetch_array($result); 
    $resultdl = mysql_query("SELECT * FROM acars_hubs"); 

    printf("<div align=\"center\"> 
    <form method=\"post\" action=\"actions/actions_editar.php\"> 
    "); 

      while ($dl = mysql_fetch_array($resultdl, MYSQL_ASSOC)){ 

     printf(" 
     <option value=".$dl["id"].">".$dl["name"]."</option>; 
     "); 

      } 

    printf(" 
     <input name=\"edit_id\" value=\"$edit_id\" type=\"hidden\"> 
     <input type=\"image\" src=\"../../images/botao_editar.PNG\" width='85' height='30'></form> 
     "); 

?> 
+0

感謝!我認爲這會對我有幫助。我想你應該改變這個問題,如果可以的話,以反映真正的問題。即,「爲下拉列表獲取數組結果」。我出於好奇,偶然讀過這篇文章,但可能找到了我在一段時間內遇到的問題的答案。 – motorbaby

+0

沒關係;我編輯了這個問題。 (PHPMyAdmin與該問題無關。) – motorbaby

2

你的意思是這樣的?

<select> 
<?php while($row = mysql_query("SELECT * FROM table")){ ?> 
<option><?=$row['column']; ?></option> 
<?php } ?> 
</select> 
+0

只有一個結果出現.. –

+0

嗯。你的桌子上有多少行? – Harry

+0

我其實有3個,但只有2個結果出現。第一個總是隱藏的。這就是我所做的:'code .... Base Operacional: <選擇名稱= \ 「集線器\」> \t \t。「); \t \t \t \t \t而($ DL = mysql_fetch_array($ resultdl)){ \t \t \t 回聲 「<選項值=」 $ DL [ 'name']。「>」。$ dl ['name']。「」; \t \t \t \t \t \t} \t \t \t \t \t \t的printf(」 \t \t \t ....' –