我知道我已經錯誤地編碼了這個,但似乎無法找到一種方法來糾正它。目的是要顯示下拉列表,填入mysql數據庫的結果。它目前正在爲每個地址顯示一個下拉菜單。我知道這是爲什麼發生,但似乎無法糾正它。回聲是否應該在while循環之外?或者位置正確但在其他地方錯了?如果有人可以檢查它,並告訴我我在哪裏與它錯誤,這將是好事。非常感謝。php while循環輸出產生每個項目的選擇
<?php
$customer = mysql_real_escape_string($_GET["customer"]);
$con = mysql_connect("localhost","root","");
$db = "sample";
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db, $con);
$query_rs_select_address2 = sprintf("SELECT * FROM company_com where idcode_com = '$customer'");
$rs_select_address2 = mysql_query($query_rs_select_address2, $con) or die(mysql_error());
$row_rs_select_address2 = mysql_fetch_assoc($rs_select_address2);
$totalRows_rs_select_address2 = mysql_num_rows($rs_select_address2);
while ($row_rs_select_address2 = mysql_fetch_assoc($rs_select_address2))
{
$address=$row_rs_select_address2['address1_com']. " ". $row_rs_select_address2['address2_com']. " ". $row_rs_select_address2['address3_com']. " ". $row_rs_select_address2['town_com']. " ". $row_rs_select_address2['postcode_com'];
echo '<select name="customer">'.'<option value="">Select delivery address</option>'.'<option value="address">'.$address.'</option>'.'</select>';
}
?>
完美。謝謝 – bollo