我有以下下拉列表

<select name="SelP">
    <option value="0">Please Select...</option>
    <option value="35">LS1</option>
    <option value="35">LS2</option>
    <option value="35">LS3</option>
    <option value="35">LS4</option>
    <option value="35">Postcode not Listed</option>
</select>


而且我已经写了PHP像这样工作

<?php
//Sample Database Connection Syntax for PHP and MySQL.
//Connect To Database
$hostname="localhost";
$username="alloytes_achenry";
$password="**PASSWORD HERE**";
$dbname="alloytes_acquote";
$usertable="LocationTable";
$postcode="postcode";
mysql_connect($hostname,$username, $password) or die ("    <html>%MINIFYHTML4333ddb1f6ba50276851b9f9854a5c817%</html>");
mysql_select_db($dbname);
# Check If Record Exists
$query = "SELECT * FROM $usertable WHERE minimumprice = 35";
$result = mysql_query($query);
if($result)
{
while($row = mysql_fetch_array($result))
{
$postcode = $row["$postcode"];
echo "$postcode";
}
}
?>


这可以很好地工作并返回邮政编码值。现在,我需要编辑PHP以返回$ postcode和$ minimumprice,然后用邮政编码作为文本并以$ minimumprice作为值(value =“ $ minimumprice”)填充表。

任何建议从哪里开始将不胜感激

谢谢

亨利

测试代码1

<?php
//Sample Database Connection Syntax for PHP and MySQL.
//Connect To Database
$hostname="localhost";
$username="alloytes_achenry";
$password="f(6@g0^O#2kT";
$dbname="alloytes_acquote";
$usertable="LocationTable";
$postcode="postcode";
$minimumprice="minimumprice";
mysql_connect($hostname,$username, $password) or die (" <html>%MINIFYHTML4333ddb1f6ba50276851b9f9854a5c817%</html>");
mysql_select_db($dbname);
# Check If Record Exists
$query = "SELECT * FROM $usertable";
$result = mysql_query($query);
if($result)
{
while ($row = mysql_fetch_assoc($result)) {
$postcode = $row['postcode'];
$minimumprice = $row['minimumprice'];
echo <<<EOL
<option value="$minimumprice">$postcode</option>

EOL;
}
}
?>
</form>


返回邮政编码,有什么想法吗?

谢谢

最佳答案

像这样吗

while ($row = mysql_fetch_assoc($result)) {
   $postcode = $row['postcode'];
   $minimumprice = $row['minimumprice'];
   echo <<<EOL
<option value="$minimumprice">$postcode</option>

EOL;
}


注意使用heredoc

09-13 10:56