doushi1957 2016-05-23 20:06
浏览 13

PHP - 使用某种循环来询问另一种形式

I've got this so far:

$result=mysqli_query($conn,$sql_query);
$in = mysqli_fetch_array($result)[0];
?>
<table>
    <tr>
    <th>ID:</th>
    <th>Item:</th>
    <th>Quantity:</th>
    <th>Sell</th>
    </tr>
<?php
$ID = 0;


foreach (explode(";", $in) as $element) {
        $ID = $ID + 1;
        $element = trim($element);
        if (strpos($element, " ") !== false ) {
                list($car, $number) = explode(" ", $element);
                $Form = "<form method = 'post'> <br> <input type ='submit' name = '$ID' value = 'Sell!' <br> </form>";
                ?>
                <tr>
                    <td><?php echo $ID; ?></td>
                    <td><?php echo $car; ?></td>
                    <td><?php echo $number; ?></td>
                    <td><?php echo $Form; ?></td>
                </tr>
                <?php


        }

}

echo "</table>";

What I was wondering was two things: 1. How can I target every single button as it could range from 1 to 100+ I presume it would use some sort of loop? Not sure how it would work though

  • 写回答

1条回答 默认 最新

  • dongzhuo1880 2016-05-23 20:24
    关注

    First, you've got a typo, you didn't close the button tag here:

    $Form = "<form method = 'post'> <br> <input type ='submit' name = '$ID' value = 'Sell!' /><br> </form>";
    // here .................................................................................^
    

    Second, as I mentioned in the comments, clicking is going to handled by Javascript as PHP runs on the server and has nothing to do with the user's actions.

    You can do that with jQuery pretty easily, for example:

    $("input[type='submit']").click(function(e){
        e.preventDefault();
        alert("do stuff!");
    });
    

    There are tonnes of tutorials on event handling with Javascript, it's a bit too broad to answer on Stack Overflow.

    评论

报告相同问题?

悬赏问题

  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了