gpt4 book ai didi

PHP MYSQL 打印

转载 作者:行者123 更新时间:2023-11-29 17:26:08 25 4
gpt4 key购买 nike

我有一个取决于商店编号的结果列表,每个商店编号都打印了其所有信息,第一个选项“全部”显示所有商店编号的信息,我希望选项“全部”仅显示信息来自 1、2 和 3 号商店,但不是全部。

这是我的代码:

<?php $store_number=$_REQUEST["store_number"]; ?>
<form name="selecciona" action="despl_probl.php" method="post">
<td> <select name="store_number" id="store_number">
<?php print(($store_number=='0'?'<option value="0"
selected>ALL</option>':'<option value="0">ALL</option>')) ?>
<?php print(($store_number=='1'?'<option value="1" selected>Store
1</option>':'<option value="1">Store 1</option>')) ?>
<?php print(($store_number=='2'?'<option value="2" selected>Store
2</option>':'<option value="2">Store 2</option>')) ?>
<?php print(($store_number=='3'?'<option value="3" selected>Store
3</option>':'<option value="3">Store 3</option>')) ?>
<?php print(($store_number=='4'?'<option value="4" selected>Store
4</option>':'<option value="4">Store 4</option>')) ?>
<?php print(($store_number=='5'?'<option value="5" selected>Store
5</option>':'<option value="5">Store 5</option>')) ?>

最佳答案

为了扩展我的评论,您可以执行以下操作,以便有一个好的方法来显示您需要的数据;

<form name="selecciona" action="despl_probl.php" method="post">
<td>
<select name="store_number" id="store_number">
<?php
$store_number=$_REQUEST["store_number"];
// Select the right option for this - will only print the one it finds
switch ($store_number)
{
case "0" : {
print "<option value='0' selected>Store 0</option>";
break;
}
case "1" : {
print "<option value='1' selected>Store 1</option>";
break;
}
case "2" : {
print "<option value='2' selected>Store 2</option>";
break;
}
case "3" : {
print "<option value='3' selected>Store 3</option>";
break;
}
case "4" : {
print "<option value='4' selected>Store 4</option>";
break;
}
case "5" : {
print "<option value='5' selected>Store 5</option>";
break;
}
default : {
// Default to print the right one at the right time
print "<option value='{$store_number}'>Store {$store_number}</option>";
}
}
?>

稍微整洁一点、对订单更好的做法是执行如下操作;

            <?php
$store_number=$_REQUEST["store_number"];
$max_option_num = 5;
for ($i = 0; $i <= $max_option_num; $i++)
{
$selected = "";
if ($i == $store_number) $selected = "selected";
print "<option value='{$store_number}' {$selected}>Store {$store_number}</option>";
}
?>

来自新的解释;

            $store_number=$_REQUEST["store_number"];
if ($store_number == "0")
{
print "<option value='0' selected>All</option>";
}
else
{
// Print the "All" first to have this there ready
print "<option value='0'>All</option>";
// These will be your stored & retrieved values
$numbers_from_database = array(1, 4, 6, 28, 33, 56);
foreach ($numbers_from_database as $store_num)
{
$selected = "";
if (store_num == $store_number) $selected = "selected";
print "<option value='{$store_num}' {$selected}>Store {$store_num}</option>";
}
}

关于PHP MYSQL 打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50952833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com