根据SELECT命令中的结果数输入字段

时间:2013-10-29 19:55:27

标签: php html mysql sql

是否有合适的方法根据SELECT中的结果获取输入表单?我有这个,但当它被发布到下一页时,只显示最后一个结果。

<?php 

$query = sprintf("SELECT promocost FROM Items, Promotions, Vendor_Prices, Vendors
WHERE Items.itemid = Promotions.itemid AND
Vendors.vendorid = Promotions.vendorid AND
Vendor_Prices.vendorid = Vendors.vendorid AND
Vendor_Prices.itemid = Items.itemid AND
promoid = '$promoid'");

$result =mysql_query($query);

if (!$result) {
$message  = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
while($row = mysql_fetch_assoc($result)) {
$models = $row['promocost'];
echo "<input type='text' name='promocost[]'/>";
}
?>

编辑: 拿出不必要的变量。

<?php 

$query = sprintf("SELECT promocost FROM Items, Promotions, Vendor_Prices, Vendors
WHERE Items.itemid = Promotions.itemid AND
Vendors.vendorid = Promotions.vendorid AND
Vendor_Prices.vendorid = Vendors.vendorid AND
Vendor_Prices.itemid = Items.itemid AND
promoid = '$promoid'");

$result =mysql_query($query);

if (!$result) {
$message  = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
while($row = mysql_fetch_assoc($result)) {
echo "<input type='text' name='promocost[]'/>";
}
?>

0 个答案:

没有答案