douwang9650 2016-08-06 14:57
浏览 61
已采纳

PHP,MySQL,HTML / CSS和javascript - 带有模态框弹出窗口的循环和按钮

So I've been breaking my brain over this one and I still can't figure it out. I have only basic knowledge of PHP and Modal Boxes and Javascript. So here's my concern...

I have PHP getting MySQL data from my database and placing this data in a table on my website [Bear in mind, this is a website for a fastfood restaurant]. I have a while loop that runs and adds each record in a table, and I add an ORDER button for each item. Each button is intended to open a modal box with the relevant item's information (so that I can add it to the shopping cart: i do have the shopping cart in order though).

THE PROBLEM:
Only the [ORDER] Button of the first item opens a modal box. The other buttons DON'T OPEN UP MODAL BOXES.

<?php
$con = mysqli_connect("localhost","root","root","mcd");
if(!$con){
    die("Can not connect".mysql_error());
}
$query = mysqli_query($con, "select * from pizza");
echo "<table border=1 align='center' width=50%>
<tr>
<th>Name</th>
<th>Medium</th>
<th>Large</th>
</tr>";
    while ($record = mysqli_fetch_array($query)) {
        echo "<tr>";
        echo "<td align='right'>".$record['pizzaName']."</td>";
        echo "<td align='right'> R".$record['PriceMedium']."</td>";
        echo "<td align='right'> R".$record['PriceLarge']."</td>";
        echo "<td align='right'> <input id='myBtn' type='button' value='ORDER'/>";
        echo "</tr>";
   }
   echo "</table>";
?>
  • 写回答

1条回答 默认 最新

  • drpph80800 2016-08-06 20:55
    关注

    I believe your problem come from the fact that your input has a id defined but no class.

    As Id are intended to be unique on a page, if you bind a javascript function on elements selected by id, only the first element having this id will be bound.

    I suggest you use

    class='myBtn'
    

    instead of

    id='myBtn'
    

    then adapt your javascript part accordingly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决