hey i am trying to add a products from different product pages into one shopping cart for example if i chose a product from asus page and another product from acer page it will display both of them in one shopping cart but now i get an error which says
select name from asus where serial=1
Column 'name' in field list is ambiguous
I created different table for each product
CREATE TABLE asus
(
serial int(11),
name varchar(20),
price float(),
picture varchar(80)
);
CREATE TABLE acer
(
serial int(11),
name varchar(20),
price float(),
picture varchar(80)
);
CREATE TABLE lenovo
(
serial int(11),
name varchar(20),
price float(),
picture varchar(80)
);
This is the function for getting the name and price :
function get_product_name($pid){
$result=mysql_query("select name from asus,acer,lenovo
where serial=$pid") or die("select name from products where serial=$pid"."<br/><br/>".mysql_error());
$row=mysql_fetch_array($result);
return $row['name'];
}
function get_price($pid){
$result=mysql_query("select price from asus,acer,lenovo where serial=$pid") or die("select name from products where serial=$pid"."<br/><br/>".mysql_error());
$row=mysql_fetch_array($result);
return $row['price'];
}
This is the function for addtocart,product exist and get total:
function get_order_total(){
$max=count($_SESSION['cart']);
$sum=0;
for($i=0;$i<$max;$i++){
$pid=$_SESSION['cart'][$i]['productid'];
$q=$_SESSION['cart'][$i]['qty'];
$price=get_price($pid);
$sum+=$price*$q;
}
return $sum;
}
function addtocart($pid,$q){
if($pid<1 or $q<1) return;
if(is_array($_SESSION['cart'])){
if(product_exists($pid)) return;
$max=count($_SESSION['cart']);
$_SESSION['cart'][$max]['productid']=$pid;
$_SESSION['cart'][$max]['qty']=$q;
}
else{
$_SESSION['cart']=array();
$_SESSION['cart'][0]['productid']=$pid;
$_SESSION['cart'][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']){
$flag=1;
break;
}
}
return $flag;
}
This is for add to cart button in every product page:
<button type="button" title="Add to Cart" class="button btn-cart"onclick="addtocart(<?php echo $row['serial']?>)" />
This for the shopping cart page:
<?php
if(is_array($_SESSION['cart'])){
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
$pid=$_SESSION['cart'][$i]['productid'];
$q=$_SESSION['cart'][$i]['qty'];
$pname=get_product_name($pid);
$price=get_price($pid);
if($q==0) continue;
?>
<tr bgcolor="#FFFFFF"><td><?php echo $i+1?></td><td>
<?php echo $pname?>
</td>
<td>RM
<?php echo $price?>