...

View Full Version : count the quantity of each product



era_zul
03-14-2009, 07:23 PM
hye..
i've an assigment to do that i need to count the quantity of each product if user click it more than 1 time..so i need to know the coding to complete this task. Below is my existing coding..can anyone help me where and what coding that must i add in here..?:confused:


<?php
require_once( "dblib.php" );
session_start();
$products = get_products();
$categories = get_categories();

if(isset ($_SESSION['username']))
$username = $_SESSION['username'];
else
$username = 'Guest';
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Baby's Store</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {
color: #FFFFFF;
font-weight: bold;
}
.style9 {color: #660000; font-weight: bold; }
-->
</style>
</head>
<script>
function buy( prod_id, cat_id )
{
document.getElementById( 'prod_id' ).value = prod_id;
document.getElementById( 'cat_id' ).value = cat_id;
document.getElementById( 'buyform' ).submit();
return null;
}
</script>
<body>
<form id="buyform" action="add.php" method="post">
<input type="hidden" name="prod_id" id="prod_id" value="" />
<input type="hidden" name="cat_id" id="cat_id" value="" />
</form>
<table width="1145" height="400" border="2" align="center" bordercolor="#330033" bgcolor="#FF9999">
<tr>
<!-- banner -->
<td height="44" colspan="2" valign="top"><img src="banner.jpg" width="1133" height="60"></td>
</tr>
<tr>
<!-- menu 1 -->
<td height="23" colspan="2" valign="top"><div align="center" class="style1">:: <a href="index2.php?home">HOME</a> :: <a href="index2.php?help">HELP</a> :: FAQ ::
<?php
if($username=='Guest')
{ echo '<a href="index2.php?login">LOGIN</a>'; }
else
{ echo '<a href="index2.php?logout">LOGOUT</a>'; }
?>

:: <a href="index2.php?register">REGISTER</a> ::</div></td>
</tr>
<tr>
<!-- menu 2 left column -->
<td width="214" valign="top"><br>
<p><b>Welcome <?php echo ($username) ?></b></p>

<strong>Baby's Categories</strong><strong>
<!--This is menu section-->
</strong>
<ul>
<?php foreach ($categories as $category)
{ ?>
<li><a href="index2.php?catid=<?php echo( $category['cat_id'] ); ?>" title="Display products of this category"><?php echo( $category['name'] ); ?></a></li>
<?php
} ?>
<p>&nbsp;</p>
</ul> </td>
<!-- body right column -->
<td width="913" align="left" valign="top" bordercolor="#FFFFFF"><p><br>
<!-- table dlm body -->
<table width="903" height="120" border="0">
<tr>
<td>
<table width="908" height="93" border="0" align="center">
<tr>
<td width="563">
<!--catalog-->
<?php
if (isset($_GET['help']))
{ include 'help.php'; }

else if (isset($_GET['logout']))
{ include 'logout.php'; }

//else if (isset($_GET['forgot']))
//{ include 'forgot.php'; }

else if (isset($_GET['checkout']))
{ include 'checkout.php'; }

else if (isset($_GET['register']))
{
if ($_GET['login'] == 'success')
{ echo 'Your form is submitted'; }
else if($_GET['login'] == 'failed')
{ echo 'Please fill all the field in the form'; }
include 'registerform.php';
}

else if (isset($_GET['catid']))
{
$catid = $_GET['catid'];
$products = get_product_by_category($catid);
?>
<table width="100%">
<strong>PRODUCTS</strong>
<!--This is content section-->
<p></p>
<?php foreach( $products as $product )
{ ?>
<tr>
<td width="40%"><?php echo( $product['p_name'] ); ?></td>
<td width="15%" align="center"><img src=product_image/<?php echo $product['p_id'] ?>.jpg></td>
<td width="15%" align="right">$<?php echo( $product['p_price'] ); ?></td>
<td width="30%" align="center"><a href="javascript:buy( <?php echo( $product['p_id'] ); ?>,
<?php echo( $catid ) ; ?> );">add to cart</a></td>
</tr>
<?php
} ?>
</table>
</td>
<td width="335" valign="top"><strong>SHOPPING CART</strong>
<!--shopping cart-->
<?php
if( isset( $_SESSION['cart'] ) )
{
?>
<!-- CART : <?php echo( join( ",", array_keys( $_SESSION['cart'] ) ) ); ?> -->
<table width="97%" height="65" cellpadding="5" cellspacing="0">
<tr>
<td><u>Product</u></td>
<td><u>Price</u></td>
<td><u>Qty</u></td>
</tr>
<?php
$qty = 0; $i=0;
foreach( array_keys( $_SESSION['cart'] ) as $product )
{
$info = product_info( $product );
?>
<tr>
<td width="52%"><?php echo( $info['p_name'] ); ?></td>
<td width="25%"><?php echo( $info['p_price'] ); ?>
<div align="center"></div></td>
<?php $total += $info['p_price']?>
<td width="23%"><?php if ($info['p_id']==$info['p_id'])
$qty++; echo $qty;?>
</td>
</tr>
<?php
//$i++;
}?>
<tr>
<td><hr><strong>Total</strong></td>
<td><hr><strong><?php echo $total; ?></strong></td>
<td><hr><strong>
<?php $t_qty += $qty;
echo $t_qty; ?> </strong>
</td>
</tr>
<tr>
<td colspan="3" align="center"><a href="index2.php?checkout">Checkout</a></td>
</tr>
</table>
</td>
<?php
}
}
else if (isset($_GET['login']))
{ include 'loginform.php'; }

else if (isset($_GET['bad']))
{
echo 'Bad login or password, please try again';
include 'loginform.php';
}
else
{ include 'home.php'; }?>
</tr>
</table>
</td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="2" valign="top"><div align="center" class="style9">Copyright &copy; 2009 babyonline.com </div></td>
</tr>
</table>

</body>
</html>

sea4me
03-14-2009, 09:14 PM
Wrap your code with the PHP tag instead of the CODE tag

Press edit and then change the CODE tags to PHP tags



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum