【问题标题】:Post multidimensional arrays with a form使用表单发布多维数组
【发布时间】:2015-08-01 14:25:32
【问题描述】:

我有一个产品列表,我正在尝试通过一个按钮将其添加到购物车中,仅选择数量大于 0 的那些产品。

如果我在每个产品旁边放置添加到购物车按钮,我可以做到这一点,然后我可以通过 POST 获取 id,但是如何用一个按钮添加多个产品?

有什么想法吗?

谢谢

【问题讨论】:

  • 我猜你正在开发一个网络应用程序?你在运行 PHP 吗?节点.js ?红宝石? ....你是客户端吗? HTML5 / Javascript ?你在使用一些客户端或服务器框架吗?你能发布你当前的代码吗?

标签: arrays multidimensional-array shopping-cart


【解决方案1】:

感谢您的回复。

这是我的代码

$rez = mysqli_query($kon, "SELECT * FROM products");
echo "<form action=\"\" method=\"post\">";
 while($red = mysqli_fetch_assoc($rez)){
                        $niz = array(
                                array($red["id"],0)
                        );
                      echo "<tbody class=\"js--isotope-target col-sm-12 js--cat-1\">
                            <tr class=\"cart_table_item\">
                              <td rowspan=\"3\" class=\"product-thumbnail\"><img src=\"images/upload/". $red["id"] .".jpg\"></td>
                              <td class=\"product-name\"><a href=\"#\">Appel</a> ( <span style=\"font-size:14;font-weight:bold;color: #71a866;\">€18</span> )</td>
                            </tr>
                            <tr>
                                <td>". $red["info"] ."</td>
                            </tr>
                            <tr>
                            <td>
                            <div class=\"quantity  js--quantity\">
                              <input type=\"button\" name=\"btnQua\" value=\"-\" class=\"quantity__button  js--minus-one  js--clickable\" style=\"width:18px;height:24px;\">
                              <input type=\"text\" name=\"quantity\" value=\"1\" class=\"quantity__input\" disabled style=\"width:24px;height:24px;\">
                              <input type=\"button\" name=\"btnQua\" value=\"+\" class=\"quantity__button  js--plus-one  js--clickable\" style=\"width:18px;height:24px;\">
                            </div>
                            <a class=\"btn btn-primary--transition\" href=\"#\" style=\"padding:3px 7px;\">
                              <!--<span class=\"glyphicon glyphicon-plus\"></span>--><span class=\"glyphicon glyphicon-shopping-cart\"></span>
                            </a>

                            </a>
                            </td>
                            </tr>
                          </tbody>
                          <button type=\"submit\" name=\"btnSubmit\">Add everything to the cart</button>";
                    }
                echo "</form>";

因此我认为我需要二维数组,我可以在其中放置产品的 ID 和数量。数组中的数量值必须根据每个产品的输入字段(数量)进行更新,而我必须通过 POST 传递它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-15
    • 1970-01-01
    • 2019-07-26
    相关资源
    最近更新 更多