1、cart.php 购物车
<?php
session_start();
$conn=mysql_connect("localhost","root","admin");
mysql_select_db("songyu");
//检查数组元素出现次数
function check_count($array,$element)
{
$times=0;
for($i=0;$i<count($array);$i++)
{
if($element==$array[$i])
{
$times++;
}
}
return $times;
}
if(isset($_GET["p_id"]))
{
$p_id=$_GET["p_id"];
}
$total_price=0;
array_push($_SESSION["cart"], $p_id);
$cart=$_SESSION["cart"];
echo "your cart:<br/>";
$new_array=array_count_values($cart);
foreach ($new_array as $key => $value)
{
$sql="select * from product where id='".$key."'";
$result=mysql_query($sql);
$out=mysql_fetch_array($result);
echo $out[name]."---个数:".$value."--".($out[price]*$value)."<br/>";
$total_price=$total_price+($out[price]*$value);
}
echo "<br/><br/>";
echo "-----------总价--------------<br/>";
echo $total_price;
?>
<a href="product.php">回s</a>
2、login.php 登录页
3、product.php 产品页
4、product_index.php 产品索引页