第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

限制用戶多次將一項添加到購物車中的php

限制用戶多次將一項添加到購物車中的php

PHP
炎炎設計 2021-05-14 15:17:14
我已經在php中創(chuàng)建了一個網站。我已經在其中提供了購物車功能。當用戶單擊添加到購物車按鈕時,應將他們重定向到顯示商品的購物車頁面。下面是處理購物車代碼的library.php:<?php// load database connection scriptinclude("database_connection.php");/* * Tutorial: PHP MySQL Shopping cart * * Page: Application library * */class ShopingCart{    protected $db;    function __construct()    {        $this->db = DB();    }    /**     * get products list     *     * @return array     */    public function getProducts()    {        $query = "SELECT *  FROM `entertainment`";        if (!$result = mysqli_query($this->db, $query)) {            exit(mysqli_error($this->db));        }        $data = [];        if (mysqli_num_rows($result) > 0) {            while ($row = mysqli_fetch_assoc($result)) {                $data[] = $row;            }        }        return $data;    }    /**        * get given product details        *        * @param [integer] $id        * @return array        */       public function getProductDetails($id)       {           $id = mysqli_real_escape_string($this->db, $id);           $query = "SELECT *  FROM `entertainment` WHERE `id` = '$id'";           if (!$result = mysqli_query($this->db, $query)) {               exit(mysqli_error($this->db));           }           $data = [];           if (mysqli_num_rows($result) > 0) {               while ($row = mysqli_fetch_assoc($result)) {                   $data['id'] = $row['id'];                   $data['title'] = $row['title'];                   $data['price'] = $row['vendor_price'];                   $data['quantity'] = 1;               }           }           return $data;       }       /**        * Add new product into the cart        *        * @param [integer] $id        * @return void        */       public function addToCart($id)       {         $product = $this->getProductDetails($id);         $isFound = false;         $i = 0;實際上,我已經參考了互聯(lián)網來制作此購物車。手推車工作正常。但是問題是我需要限制用戶多次添加一個項目,用戶只能添加一個項目一次,也就是說,該項目的數(shù)量應該僅為1,當用戶嘗試向一個項目添加更多次時,他們應該警惕。誰能告訴我該如何解決?      
查看完整描述

1 回答

?
慕碼人8056858

TA貢獻1803條經驗 獲得超6個贊

通過添加以下內容,U可以從值數(shù)組中消除重復的值:


array_unique($yourArray);

如果您的數(shù)組具有這些值:


$yourArray = ['a','b','c','b'];

$array = array_unique($yourArray);

//$array = ['a','b','c'];


查看完整回答
反對 回復 2021-05-28
  • 1 回答
  • 0 關注
  • 153 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號