Function num_items ($ table, $ session ){
$ Query = "SELECT * FROM $ table WHERE session = '$ session '";
$ Result = mysql_query ($ query );
$ Num_rows = mysql_num_rows ($ result );
Return $ num_rows;
}
Function quant_items ($ table, $ session ){
$ Quant = 0;
$ Query = "SELECT * FROM $ table WHERE session = '$ session '";
$ Result = mysql_query ($ query );
While ($ row = mysql_fetch_object ($ result )){
$ Quant + = $ row-> quantity;
}
Return $ quant;
}
}
?>
/*
This part contains a description of how to create the tables on your mysql server.
# MySQL dump 6.0
#
# Host: localhost Database: kmartShopper
#--------------------------------------------------------
# Server version 3.22.25
#
# Table structure for table 'ventory'
#
Create table inventory (
Product tinytext not null,
Quantity tinytext not null,
Id int (4) DEFAULT '0' not null auto_increment,
Description tinytext not null,
Price float (10, 2) DEFAULT '0. 00' not null,
Category char (1) DEFAULT 'not null,
KEY id (id ),
Primary key (id ),
KEY price (price)
);
#
# Table structure for table 'shopping'
#
Create table shopping (
Session tinytext not null,
Product tinytext not null,
Quantity tinytext not null,
Card tinytext not null,
Id int (4) DEFAULT '0' not null auto_increment,
KEY id (id ),
Primary key (id)
);
*/
Example
Include ("shoppingcart. php ");
$ Cart = new Cart;
$ Mysql_link = mysql_connect ("localhost", "wwwrun ","");
$ Mysql_select_db ("kmartShopper", $ mysql_link)/* heh, use whatever database name you put the 2 tables under in place of kmartShopper */
?>
/* Call functions like $ cart-> add_item and such, see the code .*/
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.