gpt4 book ai didi

php - 无法使用 php 从 mysql 表中列出 LOV 中的值

转载 作者:行者123 更新时间:2023-11-28 23:11:13 25 4
gpt4 key购买 nike

无法从 mysql 表中列出 LOV 列表中的信息。我需要在下拉框中列出类别(catname),还让我知道如何选择值(catno)以进行进一步操作。

    <?php
require_once('dbconnect.php');

$selsql="SELECT catno,catname FROM category"; //catno-integer and catname-
varchar
$res=mysqli_query($con,$selsql);
//$r=mysqli_fetch_assoc($res);
if (mysqli_query($con,$selsql)) {
}
else
{
echo "No connection";
die(mysqli_error($con));
}
?>
<html>
<head>
<title>Drop down list </title>
<meta charset=UTF-8">
<meta name="viewport">
</head>
<body>
<select name="categories"
style="width:250px;"onchange="this.form.submit();">
<?php while($row=mysqli_fetch_assoc($res)):;?>
<option value="<?php echo $row[0];?>"<?php echo $row[1];?></option>
<?php endwhile;?>
<!---<option value="<?php echo $row[0];?>""<?php echo $row[1];?>"</option>->
<!----$options.='<option value="'.$row[0].'"selected>'.$row[1].'</option>'->

</select>
</body>
</html>

最佳答案

这应该有效。

<?php
require_once('dbconnect.php');

$selsql="SELECT catno,catname FROM category";
$res=mysqli_query($con,$selsql);
if ($res == '')
{
echo "No connection";
die(mysqli_error($con));
}
?>
<html>
<head>
<title>Drop down list </title>
<meta charset="UTF-8">
<meta name="viewport">
</head>
<body>
<select name="categories" style="width:250px;" onchange="this.form.submit();">
<?php while($row=mysqli_fetch_assoc($res)) {?>
<option value="<?php echo $row['catno'];?>"><?php echo $row['catname'];?></option>
<?php } ?>
</select>
</body>
</html>

关于php - 无法使用 php 从 mysql 表中列出 LOV 中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45940383/

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