我有数据库并且名为 supplier
的表.it包含不同的列,例如region,country,9xx,10xx
。
我在下拉列表中提取9xx,10xx
列。当用户选择其中任何一列时,所选值将转到执行mysql查询的页面,然后结果显示在html表中。
问题是我没有从数据库中获取传递值的记录(即supplierid:10xx或9xx),请参阅我的代码
<?php
$dbHost = 'localhost'; // usually localhost
$dbUsername = 'xxxxxxxxx';
$dbPassword = 'xxxxxxxxxx';
$dbDatabase = 'xxxxxxxxxxx';
$db = mysql_connect($dbHost, $dbUsername, $dbPassword) or die ("Unable to connect to Database Server.");
mysql_select_db ($dbDatabase, $db) or die("Could not select database.");
$supplierid = $_GET['supplier_id'];
//supplierid is 10xx or 9xx
$sql = "SELECT region,country,$supplierid FROM supplierprice order by country ASC ";
$sql_select = mysql_query($sql);
while($rows=mysql_fetch_array($sql_select))
{
if($alt == 1)
{
echo '<tr class="alt">';
$alt = 0;
}
else
{
echo '<tr>';
$alt = 1;
}
echo '
<td id="CPH_GridView1_billingmonth " style="width:40px" class="edit billingmonth '.$rows["id"].'">'.$rows["region"].'</td>
<td id="CPH_GridView1_country " style="width:101px" class="edit country '.$rows["id"].'">'.$rows["country"].'</td>
<td id="CPH_GridView1_mnc " style="width:51px" class="edit mnc '.$rows["id"].'">'.$rows[$supplierid].'</td>
</tr>';
}
?>
答案 0 :(得分:0)
您实际上是在混合使用HTML和PHP。它们可以一起使用但不能相互使用,您应该使用以下代码:
只需删除以下代码:
echo '
> <td id="CPH_GridView1_billingmonth " style="width:40px" class="edit billingmonth
> '.$rows["id"].'">'.$rows["region"].'</td>
> <td id="CPH_GridView1_country " style="width:101px" class="edit country '.$rows["id"].'">'.$rows["country"].'</td>
>
> <td id="CPH_GridView1_mnc " style="width:51px" class="edit mnc '.$rows["id"].'">'.$rows[$supplierid].'</td>
>
>
> </tr>';
>
> }
>
> ?>
并在其位置添加以下CODE
<td id="CPH_GridView1_billingmonth " style="width:40px" class="edit billingmonth '<?php.$rows["id"] ?>.'"> <? php echo $row["region"]; ?> </td>
<td id="CPH_GridView1_billingmonth " style="width:40px" class="edit billingmonth '<?php.$rows["id"] ?>.'"> <? php echo $row["country"]; ?> </td>
<td id="CPH_GridView1_billingmonth " style="width:40px" class="edit billingmonth '<?php.$rows["id"] ?>.'"> <?php echo $row["id"]; ?> </td>
<?php
}
?>
希望这有帮助。