doutui2016 2014-03-16 22:54
浏览 90
已采纳

PHP下拉列表导致无限循环

I am trying to dynamically populate a drop down list in PHP and it is causing an endless loop and my browser to crash. I do not know how to correctly get it to show all the rows in one table but I would think this would be a relatively simple fix. The while loop might be throwing it off. Let me know if you need more information I am following this example but mine is written in PDO:

Dynamic drop down list using html and php

<h3>Company Listing</h3>
           <select name='companies'>
            <option value="">--- Select ---</option>
          <?php
          //gets user's info based off of a username.
    $query = "SELECT business_name FROM Businesses";

    try 
    {
        $stmt   = $db->prepare($query);
        $result = $stmt->execute($query_params);

    }
    catch (PDOException $ex) {
    }

//fetching all the rows from the query
$profileRow = $stmt->fetch();
while ($profileRow) 
{ 
?>

<option value="<?php echo $profileRow['business_name']?>"><?php echo $profileRow['business_name']?></option>

<?php
}
?>
    </select>
          <p></p>
  • 写回答

2条回答 默认 最新

  • ds2321 2014-03-16 22:57
    关注

    $profileRow is not changing . so it will always be true

    You need to do it like this

    while($profileRow = $stmt->fetch())

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理