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

Php 根据SELECT命令中的结果数输入字段,php,html,mysql,sql,Php,Html,Mysql,Sql,是否有一种合适的方法根据您选择的结果的多少来获取输入表单?我有这个,但是当它被发布到下一页时,只会显示最后一个结果 <?php $query = sprintf("SELECT promocost FROM Items, Promotions, Vendor_Prices, Vendors WHERE Items.itemid = Promotions.itemid AND Vendors.vendorid = Promotions.vendorid AND Vendor_Prices

是否有一种合适的方法根据您选择的结果的多少来获取输入表单?我有这个,但是当它被发布到下一页时,只会显示最后一个结果

<?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[]'/>";
}
?>

我猜处理并不是完全在循环中完成的:哪里使用了
$models
?这可能用于设置输入的值。在循环之外使用它将导致“最后结果”行为。$models在这里实际上是不相关的。我只是忘了把它拿出来!基本上,当我运行这段代码时,我会收到每个结果的输入字段。但是只有最后一个结果会发布。也许只有一个结果?检查mysql\u num\u行
<?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[]'/>";
}
?>