session_start(); @mysql_connect('mysql.leonidchemicals.net','leonidch_leoniduse','#leonid23378354') or die("Bad Doughnut for you, please try again later"); @mysql_select_db('leonidch_leonid') or die("Bad Doughnut for you, please try again later"); ?> session_start(); function get_product_name($pid){ $result=mysql_query("select * from products where slno=$pid"); $row=mysql_fetch_array($result); return $row['p_name']; } function get_product_size($pid){ $result1=mysql_query("select * from products where slno=$pid"); $row1=mysql_fetch_array($result1); return $row1['p_package']; } function get_qty($pid){ $result=mysql_query("select product.*,price.* from product,price where product.PID=price.PID and price.PRID=$pid"); //$result=mysql_query("select * from price where PID=$pid"); $row=mysql_fetch_array($result); $QTY=$row['P_QTY']; $max=count($_SESSION['cart']); for($i=0;$i<$max;$i++){ $pid=$_SESSION['cart'][$i]['productid']; $q=$_SESSION['cart'][$i]['qty']; } return $q;; } function remove_product($pid){ $pid=intval($pid); $max=count($_SESSION['cart']); for($i=0;$i<$max;$i++){ if($pid==$_SESSION['cart'][$i]['productid']){ unset($_SESSION['cart'][$i]); break; } } $_SESSION['cart']=array_values($_SESSION['cart']); } function addtocart($pid,$q,$szid){ if($pid<1 or $q<1 or $szid<1) return; if(is_array($_SESSION['cart'])){ if(product_exists($pid)) return; $max=count($_SESSION['cart']); $_SESSION['cart'][$max]['productid']=$pid; $_SESSION['cart'][$max]['szid']=$szid; $_SESSION['cart'][$max]['qty']=$q; for($i=0;$i<$max;$i++){ $pid=$_SESSION['cart'][$i]['productid']; $q=$_SESSION['cart'][$i]['qty']; $szid=$_SESSION['cart'][$i]['szid']; } } else{ $_SESSION['cart']=array(); $_SESSION['cart'][0]['productid']=$pid; $_SESSION['cart'][0]['qty']=$q; $_SESSION['cart'][0]['szid']=$szid; } } function addtocompare($pid,$q){ if($pid<1 or $q<1) return; if(is_array($_SESSION['cart1'])){ if(product_exists($pid)) return; $max=count($_SESSION['cart1']); $_SESSION['cart1'][$max]['productid']=$pid; $_SESSION['cart1'][$max]['qty']=$q; } else{ $_SESSION['cart1']=array(); $_SESSION['cart1'][0]['productid']=$pid; $_SESSION['cart1'][0]['qty']=$q; } } function product_exists($pid){ $pid=intval($pid); $max=count($_SESSION['cart']); $flag=0; for($i=0;$i<$max;$i++){ if($pid==$_SESSION['cart'][$i]['productid']) { $q2=$_SESSION['cart'][$i]['qty']; $q2=$q2+1; $_SESSION['cart'][$i]['qty']=$q2; $flag=1; break; } } return $flag; } ?>