无法从mysql表中列出LOV list中的信息。我需要在下拉框中列出类别(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>

10-04 09:53