|
 |
|
โปรเจคจบค่า ถามเรื่องแอดสินค้าลงรถเข็นคะ พอกดเลือกแล้วมันก็ยังขึ้นว่า ไม่มีสินค้าในรถเข็น อย่างเดิมอ่ะคะ |
|
 |
|
|
 |
 |
|
กำลังทำโปรเจคจบค่า เกี่ยวกับเว็บขายสินค้า
แล้วมาติดตรงแอดสินค้าลงรถเข็น
คือพอเรากดแอดสินค้าแล้วสินค้ามันจะขึ้นที่รถเข็นข้างๆ แต่มันไม่ขึ้นเลย = ="
product
<script src="../phpmydream/ajax/framework.js"></script>
<script> // เริ่มแรกก็ประกาศจาวาเพื่อไว้แอด
function addCart (id) {
var data = "id=" + id ;
var URL = "add_cart.php" ;
ajaxLoad ('post' , URL, data, "cart");
}
function readCart () {
ajaxLoad ('post', "read_cart.php", null, "cart");
}
</script>
<body>
<?
include ("../phpmydream/inc/paging.inc.php");
//รับข้อมูล Searchkey
if(!empty($_POST['searchkey']))
$searchkey=$_POST['searchkey'];
elseif(!empty($_GET['searchkey']))
$searchkey=$_GET['searchkey'];
$page=$_GET['page'];
//echo $searchkey."<br>";
mysql_connect("localhost","root","515838") or die ("ติดต่อ MySQl ไม่ได้");
mysql_select_db("phumjai") or die ("ติดต่อฐานข้อมูลไม่ได้");
$str="select * from product where proName like '%$searchkey%'order by proID";
//echo $str."<br>";
$result=mysql_query($str);
$n=mysql_num_rows($result);
//คำนวณตำแหน่งเริ่มต้นของ Page
$perPage=10;
$npage=ceil($n/$perPage);
$start=$page * $perPage;
echo " page : ";
for($i=1;$i<=$npage;$i++)
{
echo " <a href=\"proview.php?page=".($i-1)."&searchkey=$searchkey\">".$i."</a> " ;
}
echo "<br> Page ทั้งหมด : ";
$s="select * from product where proName like '%$searchkey%' order by proID limit $start,$perPage";
//echo "<br>" .$s. "<br>";
$r=mysql_query($s);
echo $npage."<br>";
if($n==0)
echo " ไม่พบสินค้า ";
else
echo " จำนวนสินค้าที่ค้นหาเจอ"." ";
echo $n. " รายการ<br>";
?></span></p>
<span class="style17"><table width="641" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#5D1F10">
<tr>
<td width="150" align="center" bgcolor="#C69C6C"><span class="style30">รหัสสินค้า</span></td>
<td width="333" align="center" bgcolor="#C69C6C"><span class="style30">รายละเอียด</span></td>
<td width="150" align="center" bgcolor="#C69C6C"><strong>ราคา</strong></td>
</tr>
<?
while($arr=mysql_fetch_array($r)) {
$id = $arr['proID'];
$proDetail = substr ($arr['proDetail'], 0, 80) . "...";
?>
<tr>
<td align="center" valign="top"><strong><? echo "PJ "?><? echo $id ?></strong></td>
<td><strong> <? echo"ชื่อสินค้า : " ?></strong><a href="pro_detail.php?id=<?=$id?>"><? echo $arr['proName'] ?></a><br>
<strong> <? echo"ประเภท : " ?></strong><? echo $arr['proCategory'] ?><br>
<strong> <? echo"รายละเอียด : " ?></strong><? echo $proDetail?><br>
<span class="style33"> *ราคายังไม่รวมค่าขนส่ง</span>
<?
if(isset ($_SESSION['login']))
echo"<input type=button value=หยิบใส่รถเข็น onClick=\"addCart ($id)\" />"; //ตรงนี้เป็นส่วนที่ให้แอดข้อมูลไปที่รถเข็น
?></td>
<td align="left" valign="middle"><strong><span class="style28"> </span></strong>
<? echo $arr['proPrice'] ?><? echo ".00 บาท" ?></td>
</tr>
<?
}
?>
</table>
</body>
อันนี้เป็นหน้าที่ใช้สำหรับแอดคะ แต่มันไม่ขึ้น TT^TT
add_cart
<?
session_start ();
$sid = session_id ();
$proID = "";
if (isset ($_POST['id'] ) ) {
$proID = $_POST['id'];
}
else {
exit;
}
mysql_connect("localhost","root","515838") or die ("ติดต่อ MySQl ไม่ได้");
mysql_select_db("phumjai") or die ("ติดต่อฐานข้อมูลไม่ได้");
$sql = "select proName, Price from product where proID = $proID;";
$result = mysql_query ($sql);
$proName = mysql_result ($result, 0, 0);
$Price = mysql_result ($result, 0, 1);
$sql = "REPLACE INTO cart VALUES ('$sid', '$proID', '$proName', '$Price', 1, NOW ());";
mysql_query ($sql);
header ("content-type: text/javascript; charset=tis-620");
echo "alert ('เพิ่มสินค้าลงในรถเข็นแล้ว');
readCart();";
?>
ช่วยหน่อยนะคะ ทั้ง งม ทั้ง งง มาหลายวันแล้ว ขอบคุณล่วงหน้าค่า
Tag : PHP, MySQL, HTML/CSS, JavaScript, CakePHP

|
|
 |
 |
 |
 |
Date :
2011-01-10 21:41:21 |
By :
FongJaeTae |
View :
878 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้เอาไว้อ่าน มันขึ้นแต่ว่าไม่มีสินค้าในรถเข็น TT^TT
read_cart
<?
session_start ();
$sid = session_id();
mysql_connect("localhost","root","515838") or die ("ติดต่อ MySQl ไม่ได้");
mysql_select_db("phumjai") or die ("ติดต่อฐานข้อมูลไม่ได้");
$sql = "select * from cart where sess_id = '$sid';";
$result = mysql_query ($sql);
header ("content-type: text/html; charset=tis-620");
$r = "<p align=center>
<img src=\"icon/cart.gif\" width=\"44\" height=\"40\" /><br/>";
if(mysql_num_rows ($result) == 0 ) {
echo "<span class=\"style15\"><strong>$r<b>ไม่มีสินค้าในรถเข็น</b></p></strong></span>";
exit;
}
$r .="<b>รายการสินค้าในรถเข็น</b></p>";
$r .="<ul>";
while ($cart = mysql_fetch_array ($result)) {
$r .="<li> {$cart['proName']} </li>";
}
$r .="</ul>";
$r .="<p align=center><span class=\"style15\"><strong><a href=check_cart.php>สำรวจรถเข็นและสั่งซื้อ</a></strong></span></p>";
echo $r;
?>
|
 |
 |
 |
 |
Date :
2011-01-10 21:55:21 |
By :
FongJaeTae |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|