基本信息
源码名称:php 购物车设计源码(含数据库表脚本以及分页)
源码大小:8.83KB
文件格式:.zip
开发语言:PHP
更新时间:2015-12-29
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
有数据操作类以及分页脚本等
有数据操作类以及分页脚本等
<?php require( "./mysql.class.php" ); class GoodsModel { private $goods_tb_name = 'goods'; private $cat_tb_name = 'category'; private $gallery_tb_name = 'goods_gallery'; public $db; public function __construct ( &$db ) { $this->db = $db; } //添加商品 public function add_goods ( $data ) { if ( $this->has_goods( $data['goods_name'], $data['goods_sku'] ) ) { return false; } else { $rs = $this->db->add( $this->goods_tb_name, $data ); if ( $rs ) { $insert_id = mysql_insert_id(); $data = array( 'goods_id' => $insert_id, 'goods_thumb' => $insert_id . '_1_thumb.jpg', 'goods_center' => $insert_id . '_2_center.jpg', 'goods_original' => $insert_id . '_3_original.jpg', ); return $this->db->add( $this->gallery_tb_name, $data ); } else { return false; } } } //添加商品之前,判断是否存在同样的商品名或者货号 public function has_goods ( $goods_name, $goods_sku ) { $sql = "SELECT * FROM {$this->goods_tb_name} WHERE goods_name = '$goods_name' OR goods_sku = '$goods_sku'"; $row = $this->db->get_row( $sql ); if ( $row ) { return true; } else { return false; } } //取出一条商品所有的信息 public function get_goods_detail ( $goods_id ) { return $this->db->get_row( "SELECT * FROM {$this->goods_tb_name} WHERE goods_id = $goods_id" ); } //更新商品 public function update_goods ( $goods_id, $data ) { return $this->db->update( $this->goods_tb_name, $data, "WHERE goods_id = $goods_id" ); } //删除商品 public function del_goods ( $goods_id ) { return $this->db->query( "DELETE FROM {$this->goods_tb_name} WHERE goods_id = $goods_id" ); } //查找商品 public function get_goods_list ( $p = '', $page_size ='' ) { $sql = "SELECT g.*,c.cat_name FROM {$this->goods_tb_name} g LEFT JOIN {$this->cat_tb_name} c ON g.cat_id = c.cat_id"; return $this->db->get_all( $sql ); } } // $g = new GoodsModel( $db ); // // print_r( $g->get_goods_list() ); // $data = array( // 'cat_id' => 7, // // 'goods_name' => '荣耀 6 (H60-L01) 3GB内存标准版 白色 移动4G手机', // // 'goods_name' => '华为 畅享5 朦胧灰 全网通版4G手机 双卡双待', // 'goods_name' => '荣耀 6 Plus (PE-TL20) 3GB内存标准版 白色 移动4G手机 双卡双待双通', // 'goods_desc' => '荣耀 6 (H60-L01) 3GB内存标准版 白色 移动4G手机', // 'goods_sku' => 10016, // 'goods_stock' => 100, // 'goods_price' => 2000, // 'is_show' => 1, // ); // $res = $g->add_goods( $data ); // // $res = $g->update_goods( 16, $data ); // // $res = $g->del_goods( 16 ); // if ( $res ) { // echo "ok"; // } else { // echo "error"; // } // print_r( $g->get_goods_detail( 16 ) ); ?>