|
|
|
ช่วยด้วยค่ะ ทำระบบ addcart แต่พอคลิก addcart แล้วมันก็เด้งขึ้นไปบนสุดของเพจเลยอ่ะคค่ะ แต่ไม่มีอะไรเกิดขึ้น ช่วยดูให้หน่อยนะคะ -/|\- |
|
|
|
|
|
|
|
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
<script type="text/javascript" src="myjs.js">
</script>
<script type="text/javascript" language="javascript" src="prototype.js">
</script>
<script language="javascript" type="text/javascript">
function addBasket(productID, Div) //เป็นฟังชั่นใช้เพิ่มสินค้าลงตระกร้าอ่ะค่ะ ใช้ ajax
{
var params = "productID="+ productID;
var url = "addBasket.php";
var Addnew = new Ajax.Updater(Div,url,{method: "get", parameters: params});
}
</script>
</head>
<body>
<div>
<? include('menubar.php'); ?>
</div>
<? include('onlineshop.inc.php');?>
<table width="1000" align="center" border="0">
<tr>
<td align="left"> <? include('sidemenu.php');?>
<div id="cart"></div>
</td>
<td>
<table width="100%" border="0">
<tr> <td width="30%"> </td>
<td width="50%"> </td>
<td> </td>
</tr>
<?php include("paging.inc.php");
$current_page=1;
if(isset($_GET['page']))
{
$current_page=$_GET['page'];
}
$rows_per_page = 9;
$start_row = paging_start_row($current_page,$rows_per_page);
$keyword=$_GET["search"];
if($keyword != "")
{
$argId=$_GET["search"];
$sql = "select distinct (Product_Name)from product as p,wearer as w ,category as t, brand as b,Color as c,material as m,size as s
where p.Product_Name like '%".$argId."%'
or p.Product_Prices like '%".$argId."%'
or p.Product_Des like '%".$argId."%'
or (w.Wearer_Description like '%".$argId."%'and w.Wearer_Id=p.Wearer_Id )
or (w.Wearer_Id=p.Wearer_Id and w.Wearer_Type like '%".$argId."%' )
or (b.Brand_Id=p.Brand_Id and b.Brand_Name like '%".$argId."%' )
or (t.Cat_Id=p.Cat_Id and t.Cat_Name like '%".$argId."%' )
or (c.Color_Id=p.Color_Id and c.Color_Name like '%".$argId."%')
or (m.Mat_Id=p.Mat_Id and m.Mat_Name like '%".$argId."%' );
or (s.Size_Description like '%".$argId."%' and s.Size_Id = p.Size_Id )
or (s.Size_Id=p.Size_Id and s.Size_Name like '%".$argId."%' )";
/*$sql= "SELECT SQL_CALC_FOUND_ROWS * from product, color,material, category WHERE ( (product.Product_Des LIKE '%".$argId."%') AND Size_Id='s1' LIMIT $start_row, $rows_per_page ;";*/
}
else
{
$argId=$_GET["argId"];
$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM product WHERE (Cat_Id ='$argId' OR Color_Id='$argId' OR Wearer_Id='$argId' OR Mat_Id='$argId' OR Product_Des LIKE '%".$argId."%') AND Size_Id='s1' LIMIT $start_row, $rows_per_page;";
if(strcmp($argId,"EDITOR")==0 or strcmp($argId,"FALL ")==0 or strcmp($argId,"CHILL OUT")==0 or strcmp($argId,"OFFICE LOOK")==0)
{
$sqlpic="SELECT * FROM headpic WHERE pic_name ='$argId' ;"; //for headpic
//headpic section
$resultpic = mysql_query($sqlpic);
while($rowpic = mysql_fetch_array($resultpic))
{
$headpic=$rowpic['pic_pict'];
}
//headpic section
}
/*else
{
$sqlpic="SELECT headpic.pic_pict FROM headpic WHERE headpic.pic_name IN (SELECT category.cat_name, color.color_name, material.mat_name FROM category, color, material WHERE category.cat_Id='$argId' OR color.color_Id='$argId' OR material.mat_Id='$argId');";
//headpic section
$resultpic = mysql_query($sqlpic);
while($rowpic = mysql_fetch_array($resultpic))
{
$headpic=$rowpic['pic_pict'];
}
//headpic section
} */
}
$result=mysql_query($sql);
$found_rows=mysql_query("SELECT FOUND_ROWS();");
$total_rows=mysql_result($found_rows,0,0);
$total_pages = paging_total_pages($total_rows, $rows_per_page);
if($total_rows==0){
echo "<caption><b> no result </b></caption>";
}
/*else {
$stop_row = paging_stop_row($start_row, $rows_per_page, $total_rows);
echo "<caption><b> product no.". ($start_row +1) . "-" . "$stop_row from total $total_rows </b></caption>";
} */
$count=0;
echo "<table border=0 align=center >";
echo "<tr><td colspan=3><div> <img src='$headpic'></div> </td></tr>"; //for headpic
while($objResult = mysql_fetch_array($result))
{
$PID = $objResult['Product_Id'];
$Pname = $objResult['Product_Name'];
$Pdesc1 = $objResult['Product_Des'];
$Pdesc = substr($Pdesc1,0,80). "..." ;
$Pprice = $objResult['Product_Prices'];
$Ppic = $objResult['Product_Pict'];
if($count==0)
{
echo "<tr> <td width=250 ><div id=product> <img width=140 src='$Ppic?Product_Id=$PID'> </div>";
echo "<div id=productName> <br><b> <a href='product_detail.php?PID=$PID'> $Pname </a> </b></div>";
echo "<div id=product> <br> $Pdesc </div>";
echo "<div id=product> <br> $Pprice Baht</div>";
echo "<div id=product> <br> <a href='#' onclick='addBasket($PID, cart)'><img src='addBag.gif'> </a> </div>"; //onclick ส่งข้าโปรดักไอดี กับ div id ที่ต้องการให้โชว์คาร์ท ไปที่ฟังชั่น addBasket ค่ะะะ
echo "</td>";
$count++;
}
else if($count==1)
{
echo "<td width=250 > <div id=product> <img width=140 src='$Ppic?Product_Id=$PID'> </div>";
echo "<div id=productName> <br><b><a href='product_detail.php?PID=$PID'> $Pname </a> </b> </div>";
echo "<div id=product> <br> $Pdesc </div>";
echo "<div id=product> <br> $Pprice Baht</div>";
echo "<div id=product> <br> <a href='#' onclick='addBasket($PID, cart)'><img src='addBag.gif'> </a> </div>";
echo "</td>";
$count++;
}
else if($count==2)
{
echo "<td width=250 > <div> <img width=140 src='$Ppic?Product_Id=$PID'> </div>";
echo "<div id=productName> <br><b><a href='product_detail.php?PID=$PID'> $Pname </a> </b> </div>";
echo "<div id=product> <br> $Pdesc </div>";
echo "<div id=product> <br> $Pprice Baht</div>";
echo "<div id=product> <br> <a href='#' onclick='addBasket($PID, cart)'><img src='addBag.gif'> </a> </div>";
echo "</td>";
echo "</tr>";
$count=0;
}
} echo "</table>";
?>
<p align="right"> <br />
<?php
$page_range=5;
$qry_str="argId=$argId";
//$total_pages = paging_total_pages($total_rows, $rows_per_page);
$pagenum = paging_pagenum($current_page, $total_pages, $page_range, $qry_str);
?>
<?
echo "page:" . $pagenum;
?>
</p>
</table>
</td>
</tr>
</table>
<div>
<? include('footer.php'); ?>
</div>
</body>
</html>
นี่เป็นโค้ด addBasket.php ค่ะ
Code (PHP)
<?
session_start();
print "<form id='form1' name='form1' method='post'>";
include("onlineshop.inc.php");
$SID= session_id();
$PID= $_GET['productID'];
$sql= "SELECT * from cart where Product_Id=$PID AND Sess_Id='$SID'";
$result = mysql_query($sql);
if(mysql_num_rows($result)==0
{
$sql= "insert into cart (Sess_Id, Product_Id, Quantity) VALUES ('$SID', '$PID',1)";
}
else
{
$sql= "UPDATE cart set Quantity=Quantity+1 WHERE Product_Id=$PID AND Sess_Id='$SID'";
}
mysql_query($sql);
$sql= "SELECT * FROM cart, product WHERE cart.Product_Id = product.Product_Id AND Sess_Id = '$SID'";
$result = mysql_query($sql);
$totalPrice = 0;
print "<table>";
while ($row=mysql_fetch_array($result))
{
$PID= $row["Product_Id"];
$Pname = $row["Product_Name"];
$Pprice = $row["Product_Prices"];
$quantity = $row["Quantity"];
print "<tr bgcolor='#C0C0C0'>";
print "<td> $Pname </td> <td> $Pprice Baht. </td> <td> $quantity items </td>";
print"<td>".($Pprice*$quantity)." Baht </td>"
print "<td><a href='#' onclick='removeBasket($PID, cart)'> PUT IT BACK </a> </td>";
print "</tr>";
print "<tr> <td colspan=6> </td> </tr>";
$totalPrice = $totalPrice + ($Pprice * $quantity);
}
print "<tr>";
print "<td colspan=3 align='right'> <b> total : $totalPrice Baht. </b> </td> </tr>";
print "</table>";
print "</form>";
?>
Tag : PHP, MySQL, Ajax
|
|
|
|
|
|
Date :
2012-01-07 13:39:12 |
By :
gellarjung |
View :
927 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print "<td><a href='#' onclick='removeBasket($PID, cart)'> PUT IT BACK </a> </td>";
สาเหตุที่มันเลื่อนขึ้นบน เพราะ <a href='#'
ที่มันไม่ทำงานเท่าที่ดูผมไม่เห็น function removeBasket เลยครับ
ผิดพลาดขออภัยครับ
|
|
|
|
|
Date :
2012-01-07 14:03:42 |
By :
yamcrocodile |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|