通过用户交互更新 MySQL 结果集,并对应用程序进行全局更改

发布于 2024-11-06 12:56:11 字数 782 浏览 1 评论 0原文

我从 MySQL 表中获取结果集并将其显示在网页上,如下所示:

<?php
  $link = mysql_connect(....);
  mysql_select_db(....);

  $sql = "select * from products where category = '" .$_POST['prod_cat']. "'";
  $rs  = mysql_query($sql, $link);

  echo "<form name='prodselect' action='prodlist.php' method='post'>";
  echo "<table>";
  $rowcount = 1;
    while ($row = mysql_fetch_array($rs))
    {
      echo "<tr>";
        echo "<td>" .$row['product_name']. "</td>";
        echo "<td><input type='checkbox' name='line_" .$rowcount. "'></td>";
      echo "</tr>";
    }
  echo "</table>";
  echo "</form>";
?>

这将显示产品列表,每个产品行都带有复选框。 用户将使用复选框选择产品。

我想在另一个网页的“待购买产品”列表中显示/保存所选产品。

请帮帮我。 谢谢。

I fetching a result set from a MySQL table and displaying it on the web page as under:

<?php
  $link = mysql_connect(....);
  mysql_select_db(....);

  $sql = "select * from products where category = '" .$_POST['prod_cat']. "'";
  $rs  = mysql_query($sql, $link);

  echo "<form name='prodselect' action='prodlist.php' method='post'>";
  echo "<table>";
  $rowcount = 1;
    while ($row = mysql_fetch_array($rs))
    {
      echo "<tr>";
        echo "<td>" .$row['product_name']. "</td>";
        echo "<td><input type='checkbox' name='line_" .$rowcount. "'></td>";
      echo "</tr>";
    }
  echo "</table>";
  echo "</form>";
?>

This displays the list of products with checkbox for every product row.
The user will select products using the checkboxes.

I want to display / save the selected products in the "Products for Purchase" list on another web page.

Please help me out.
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

话少心凉 2024-11-13 12:56:11

我可以建议您创建这样的复选框:

    echo "<td><input type='checkbox' name='products[]' value='" .$row['product_id']. "'></td>";

然后在 prodlist.php 上您可以获得数组 $_POST['products']

I can suggest you to create the checkbox like this:

    echo "<td><input type='checkbox' name='products[]' value='" .$row['product_id']. "'></td>";

then on the prodlist.php you can get the array $_POST['products']

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文