简体   繁体   English

PHP select 来自数据库的选项,结果未显示

[英]PHP select option from database, results not showing

I'm trying to get selected option data from database, my selected option in web can't show anything but an arrow我正在尝试从数据库中获取选定的选项数据,我在 web 中选择的选项只能显示一个箭头

<select>
    <?php
        $sql="SELECT * FROM `User`";
        $result=$database->getData($sql);
        while($row=mysqli_fetch_assoc($result)){
        ?>
        <option>
        <?=$row['LastName'].", " .$row['FirstName'];?></option>
    <?php }  ?>
</select>

Did u tried var_dump($result)?你试过 var_dump($result) 了吗? Is data there?有数据吗? if yes do this inside select.如果是,请在 select 内执行此操作。

<?php foreach($result as $row) : ?>
<option><?php echo $row['LastName'].", " .$row['FirstName'];?></option>
<?php endforeach; ?>

Try the below.试试下面的。 I generally find it easier to read the code when I take steps to avoid dropping in and out of php. In your original code, it looks like you have an “=“ before $row['LastName'], which doesn't look right.当我采取措施避免掉入和掉出 php 时,我通常会发现更容易阅读代码。在您的原始代码中,看起来您在 $row['LastName'] 之前有一个“=”,看起来不像正确的。

<select>
<?php
    $sql="SELECT * FROM `User`";
    $result=$database->getData($sql);
    while($row=mysqli_fetch_assoc($result)){
        echo “<option>“ . $row['LastName']. ", " .$row['FirstName'] . “</option>”;
    }
?>
</select>

I'm trying to get selected option data from database, my selected option in web can't show anything but an arrow我正在尝试从数据库中获取选定的选项数据,我在 web 中选择的选项只能显示箭头

<select>
    <?php
        $sql="SELECT * FROM `User`";
        $result=$database->getData($sql);
        while($row=mysqli_fetch_assoc($result)){
        ?>
        <option>
        <?=$row['LastName'].", " .$row['FirstName'];?></option>
    <?php }  ?>
</select>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM