2016-12-31 59 views
0

我想創建一些代碼來做一個在MySQL組件的列表。
像這樣如何創建從PHP選擇

decod - 1,2,3,4,5 

,並使其在下拉listlike這

decod (dorplist) 1 
2 
3 
4 
5 

我這個嘗試之一:

<?php 
$mysqli = mysqli_connect("host", "username", "password", "name"); 

$result = mysqli_query($mysqli, 'SELECT * FROM componnets') or die(mysqli_error(mysqli)); 



while ($row = mysqli_fetch_array($result)) { 
    $org = str_replace("," , "'>", $row['fill'].""); 
    $replace = str_replace("," , " 
    ".$org."</option><option value='", $row['fill']."'>"); 

echo "<input type='hidden' name='compo' value='".$row['compon']."'>".$row['compon'].""; 
echo "<select name='fill'>"; 
echo "<option value='".$replace."'>".$replace."</option>"; 
echo "</select>"; 
} 

// Free result set 
mysqli_free_result($result); 
/* close connection */ 
$mysqli->close(); 
?> 

,做使它輸出到XML

但我不知道如何!這樣

<input type='hidden' name='compo' value='DECODERS'>DECODERS 
<select name='fill'> 
<option value='1010'>20'>30'>40</option> 
<option value='2010'>20'>30'>40</option> 
<option value='3010'>20'>30'>40</option> 
<option value='40'>'>1010'>20'>30'>40</option> 
<option value='2010'>20'>30'>40</option> 
<option value='3010'>20'>30'>40</option><option value='40'></option> 
</select> 
<input type='hidden' name='compo' value='DECODERS'>DECODERS 
<select name='fill'> 
<option value='10'>10</option> 
</select> 
+2

這不是你的數據庫用戶名和密碼,它是:

像這樣的東西可能讓你在正確的方向開始了嗎?你是認真的嗎? – Skayo

+0

@Skayo我只是假設'主機'不能解析爲公共IP:P –

+0

當然,但你只需要獲得主機(這比獲取密碼和用戶名更容易),然後你就可以進入。 – Skayo

回答

1

I輸出首先創建<select>while循環。然後遍歷行以添加元素。

我不確定你想要通過你的str_replace調用完成什麼,所以我刪除了它們。

<?php 

$result = mysqli_query($mysqli, 'SELECT * FROM componnets') or die(mysqli_error(mysqli)); 

echo "<select name='fill'>"; 
echo "<input type='hidden' name='compo' value='".$row['compon']."'>".$row['compon'].""; 
while ($row = mysqli_fetch_array($result)) {  
echo "<option value='".$row['fill']."'>".$row['fill']."</option>"; 
} 
echo "</select>";  
mysqli_free_result($result); 
$mysqli->close(); 
?> 
+0

仍然在數據庫填充行有「,」爲一個循環..在str_replace中的 –

+0

我試圖在選擇時制動填充像1 2 3 –