douyiji3919 2018-09-20 14:30
浏览 62

if(mysqli_num_rows)while(mysqli_fetch_assoc)循环未在第一次迭代时发布正确的值,适用于下一个

My code is running a cycle that adds textareas where the user can input queries, which the div it is in also contains a dropdown with a list of servers available to run those queries in. At first it was working just fine for only the first iteration and not showing the list at all in the next dropdowns, but while I was messing with the code and pasted the query inside the cycle all dropdowns were filled but the server ID of the first textarea stopped being posted correctly, instead sending the value that's currently in the database. By other words it won't update properly.

<?php
if(mysqli_num_rows($result_query) > 0){ 
   while($rowq = mysqli_fetch_assoc($result_query)){                        
     $sql_servers = "SELECT id, name, address FROM servers ORDER BY id ASC";
     $result_servers = mysqli_query($link, $sql_servers);
 ?>
     <table>
       <form name="formStep" method="post" action="">
       <br>
       <tr>
         <textarea class="form-control scrollabletextbox" id="query<?php echo $rowq['step']?>" name="query<?php echo $rowq['step']?>"><?php echo $rowq['query'];?></textarea>
       </tr>
       <tr>
         <td width="25%" style="vertical-align:middle;"><select id="server" name="server" class="form-control input-md">
         <?php
          if (mysqli_num_rows($result_servers) > 0) { 
            while($rows = mysqli_fetch_assoc($result_servers)){ ?>
              <option value="<?php echo $rows["id"];?>" <?php if($rows['id']==$row_query2['id_server']) echo 'selected=\"selected\"' ?> ><?php echo $rows["name"];?></option>   
           <?php
           }
           }?>                      
           </select>
           </td>
           <td style="padding:10px;"><input type="submit" name="submit" formaction="save.php?i=4&id=<?php echo $id; ?>&s=<?php echo $rowq['step'];?>" class="btn btn-block btn-primary" value="<?php echo $lableSave; ?>"></td>
          </tr>
          <?php
           }
           }?>
          </form>  
         </table>

If I echo the server variable in the save.php it will not update for the new selected value in the dropdown, but it will work for all the subsequent iterations of the cycle.

Any way to solve this problem or the previous one before i started trying to hammer the code until it worked would be greatly appreciated.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 本题的答案是不是有问题
    • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
    • ¥15 C++使用Gunplot
    • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
    • ¥15 matlab数字图像处理频率域滤波
    • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
    • ¥15 ELGamal和paillier计算效率谁快?
    • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
    • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
    • ¥15 Arcgis相交分析无法绘制一个或多个图形