dongzhong5756 2017-11-25 23:50
浏览 62
已采纳

文本框空白后循环

Why are my text boxes blank after my while loop?

If I remove the while loop the data then shows?

This is the form below.

<form name="form" method="post" action=""> 
<input type="hidden" name="new" value="1" />

<p><input type="text" name="res_veop_id" placeholder="Enter VEOP ID" required value="<?php echo $row["res_veop_id"]; ?>"/></p>

<p><select class="selectpicker" name="res_title">
    <option value="<?php echo $row["res_title"]; ?>"><?php echo $row["title_name"]; ?></option>
<?php
$title_count=1;
$title_sel_query="Select * from `tbl_title` ORDER BY `title_id` asc;";
$title_result = mysqli_query($con,$title_sel_query);
while($row = mysqli_fetch_assoc($title_result)) { ?>
    <option value="<?php echo $row["title_id"]; ?>"><?php echo $row["title_name"]; ?></option>
<?php $title_count++; } ?>
    </select>

</p>
<p><input type="text" name="res_first_name" placeholder="Enter Firstname" required value="<?php echo $row["res_first_name"]; ?>"/></p>
<p><input type="text" name="res_last_name" placeholder="Enter Lastname" required value="<?php echo $row["res_last_name"]; ?>"/></p>
<p><input type="text" name="res_dob" placeholder="Enter Date of Birth" required value="<?php echo $row["res_dob"]; ?>"/></p>
  • 写回答

1条回答 默认 最新

  • doupao5296 2017-11-25 23:55
    关注

    You use the variabel $row in your code to address the values, that shall be shown on the whole page. In your while loop, you overwrite the variable $row in the loop head. Since it is a while loop it will run until $row is null. Therefore all following calls on $row will return nothing.

    I suggest you rename the variable:

    while($option = mysqli_fetch_assoc($title_result)) { ?>
        <option value="<?php echo $option["title_id"]; ?>"><?php echo 
    $option["title_name"]; ?></option>
    <?php $title_count++; } ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答