Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ทำระบบ shopping cart แล้ว มันเกิด error คือได้ทำระบบ shopping cart แล้ว มันเกิด error



 

ทำระบบ shopping cart แล้ว มันเกิด error คือได้ทำระบบ shopping cart แล้ว มันเกิด error

 



Topic : 033485

Guest




คือได้ทำระบบ shopping cart แล้ว มันเกิด error ในช่วงที่เราจะเปลี่ยนจำนวนสินค้าที่ต้องการสั่งซื้อว่า
error
Warning: array_count_values() [function.array-count-values]: Can only count STRING and INTEGER values! in C:\AppServ\www\golf_1\show_cart.php on line 74
...............................................................................

ส่วนที่มาที่ไปก็จากการกดปุ่ม บันทึกการเปลี่ยนแปลงด้านล่าง
if($change==true)
{ echo "<input name=\"$product_id\" type='text' size=1 value=$qty>";}
else { echo "<font>".$qty."</font>"; }

if($change==true)
{ echo "<div style='text-align:right; padding-right:100px;'>
<input type='hidden' name='new' value='0'>
<input type='hidden' name='save' value='true'>
<input name='' type='submit' value='บันทึกการเปลี่ยนแปลง'></div>";
}
-------------------------------------------------------------------
มันก็จะมาทำการคำนวนใหม่ แล้วแสดงผล

if($cart&&array_count_values($cart)) ----------------------------- มันฟ้อง error ทีบรรทัดนี้คะ
{ display_cart($cart,true);
}

อย่างนี้มันหมายความว่าอย่างไรคะ รบกวนทุกท่านที่รู้ช่วยด้วยนะคะ วุ่นกับมันมา 2 วันแล้วคะไม่รู้พลาดอะไรตรงไหน ถ้าต้องการข้อมูลอะไรเพิ่มเติม สอบถามได้เลยนะคะ ขอบคุณค่ะ



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2009-10-25 23:10:06 By : nut View : 1304 Reply : 12
 

 

No. 1



โพสกระทู้ ( 484 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


ลองเปลี่ยนอย่างนี้ดูนะครับ

1.เว้นวรรคให้มัน

Code (PHP)
if($cart && array_count_values($cart)) 



2.เปลี่ยนซะเลย เป็น and แทนดีก่า
Code (PHP)
if($cart and array_count_values($cart)) 







Date : 2009-10-25 23:18:11 By : onizike
 


 

No. 2



โพสกระทู้ ( 484 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


ลองเช็คค่านี้ดูนะครับ

array_count_values($cart)

error มันฟ้องสามารถนับค่าที่เป็น integer กับ string เท่านั้นนะครับ
Date : 2009-10-25 23:22:24 By : onizike
 

 

No. 3

Guest


ลองทั้ง 2 วิธีแล้วก็ยังไม่ได้คะ มีวิธีไหนอีกรึป่าวคะ

แล้ว error แบบนี้มันหมายความว่าอย่างไรคะ

ขอบคุณค่ะ
Date : 2009-10-25 23:33:17 By : nut
 


 

No. 4



โพสกระทู้ ( 1,463 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Blogger

if($cart&&array_count_values($cart)) ----------------------------- มันฟ้อง error ทีบรรทัดนี้คะ
{ display_cart($cart,true);
}

เดาเอาว่าจะเป็น
if (!empty($cart) && count($cart) > 0){
display_cart($cart,true);
}

น่ะครับ
Date : 2009-10-25 23:36:13 By : num
 


 

No. 5



โพสกระทู้ ( 484 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


พี่หนุ่มสุดยอด

จาก Code เดิม
Code เดิม(PHP)
if($cart&&array_count_values($cart)){ 
   display_cart($cart,true);
} 





คุณไม่ได้กำหนดเงื่อนไขให้มันอ่ะครับ ตัวอย่างเช่น
ผมให้ $cart มีค่าเท่ากับ 1 และ array_count_values($cart) มีค่าเท่ากับ 1
เวลาเขียนออกมามันจะอยู่ในรูปแบบนี้ครับ

Code ตัวอย่าง(PHP)
if (1 && 1 ){
   display_cart($cart,true);
}


ซึ่ง 1 และ 1 มันไม่มีความหมายเช็คค่าไม่ได้ครับ ไม่เลยไม่เข้าเงื่อนไข IF ครับ
Date : 2009-10-25 23:49:29 By : onizike
 


 

No. 6

Guest


ทำตามที่คุณ num บอกปรากฎว่ามันไม่ error แล้วเข้า if นี้หละ แต่มัน ตีค่าเป็น 0 เลยคะ

error ที่แจ้งไป


แก้ตามที่คุณ num บอก
Date : 2009-10-25 23:50:50 By : ืnut
 


 

No. 7



โพสกระทู้ ( 1,463 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Blogger

ขอดูโค้ดข้างใน display_cart หน่อยครับ
ลอง var_dump($cart); ออกมาดูด้วยครับ เพื่อดูว่า $cart มีข้อมูลอะไรบ้าง

แต่ดูคร่าวๆ แล้วน่าจะเป็นที่ textbox ยังไม่ได้กำหนดค่า value น่ะครับ
Date : 2009-10-26 00:03:15 By : num
 


 

No. 8

Guest


คุณหนุ่มคะ (กรณีที่เลือกสินค้ามาแสดงไม่เป็นไรคำนวณปกติ แต่พอเปลี่ยนจำนวนใน textbox แล้วมันกลับมา clear ค่าใน textbox เป็นค่าว่าง แล้ว error ดังกล่าวข้างต้นคะ )

function display_cart($cart,$change)
{
global $items;
global $total_price;
echo "<form action='show_cart.php' method='post'>
<table width='850' cellspacing='1' bordercolor='#000000' cellspacing='0' align='center'>
<tr align='center' valign='middle' bgcolor='#333333' class='white12'>
<td width='62' class='white12'> Product ID</td>
<td width='138' height='35'>PRODUCT PICTURE</td>
<td width='285'>PRODUCT NAME </td>
<td> PRICE</td>
<td> QUATITY</td>
<td> TOTAL</td>
<td width='81'>&nbsp;</td>
</tr>";
// display product rows
foreach ($cart as $product_id =>$qty)
{ $product=get_product_detail($product_id);
echo " <tr valign='middle' bgcolor='#C0C0C0'>
<td align='center' class='black12'><strong class='black12'>".$product[p_id]."</strong></td>
<td align='center'><a href='p_detail.php?p_id=".$product[p_id]."'><img src='admin/product_images/".$product[p_picname1]."' width='50' height='35' border='0'></a></td>
<td align='center' class='producttopic'><a href='p_detail.php?p_id=".$product[p_id]."'>". $product[p_name]."</a> </td>
<td width='80' align='center' class='red12'>". $product[p_price]."</td>
<td width='80' align='center' class='white11'>";
if($change==true)
{ echo "<input name=\"$product_id\" type='text' size=1 value=$qty>";}
else { echo "<font>".$qty."</font>"; }
echo "</td>";
echo "<td width='80' align='center'><span class='red12'>".number_format($product['p_price']*$qty,2). "</span></td>
<td width='81' align='center'><a href=delete_cart.php?p_id=".$product[p_id]."><img src='admin/images/scissors.png' alt='Delete' border='0'/></a> </td>
</tr>";
} // end foreach
echo "<tr valign='middle' bgcolor='#C0C0C0'>
<td colspan='4' align='center' class='black12'><b>Product in Cart</b></td>
<td width='80' align='center' class='white11'>".$items."</td>
<td width='80' align='center'>".number_format($total_price,2)."</td>
<td width='81' align='center'></td>
</tr>
<tr valign='middle' bgcolor='#000000' class='white11'>
<td colspan='4' align='right'><strong>Total : </strong></td>
<td colspan='3' align='center' bgcolor='#191919'><span class='producttopic'><strong>".number_format($total_price,2)." Bath</strong></span></td>
</tr>
<tr valign='middle' bgcolor='#000000' class='white11'>
<td colspan='4' align='right'><strong>Discount Code : </strong></td>
<td colspan='3' align='center' bgcolor='#191919'><input name='code' type='text' ></td>
</tr>
<tr valign='middle' bgcolor='#000000' class='white11'>
<td colspan='4' align='right'><strong>Merchandise Total : </strong></td>
<td colspan='3' align='center' bgcolor='#191919'>
<input name='code' type='text' value='".number_format(($total_price-($total_price*5/100)),2)."' readonly></td></tr>";
if($change==true)
{ echo "<tr><td colspan='7'><div style='text-align:right; padding-right:100px;'>
<input type='hidden' name='new' value='0'>
<input type='hidden' name='save' value='true'>
<input name='' type='submit' value='ºÑ¹·Ö¡¡ÒÃà»ÅÕè¹á»Å§'></div></td></tr>";
}
echo "</table></form>";
} // end function display_cart



function get_product_detail($product_id)
{
if(!$product_id || $product_id==''){
return false; }
include ("_conn/conn_db.php");
$sql="select * from product where p_id='$product_id' ";
mysql_query("SET NAMES 'tis620' ");
$query=mysql_query($sql);
if($query=='') {
return false; }
$result=mysql_fetch_array($query);
return $result;
} // // end function get_product_detail;
Date : 2009-10-26 10:43:12 By : nut
 


 

No. 9



โพสกระทู้ ( 1,463 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Blogger

ขอโค้ดส่วน update ด้วยครับ
Date : 2009-10-26 11:23:59 By : num
 


 

No. 10

Guest


// ส่วนที่เรียกมาโชว์คะ
<?
include ("_include/function.php");
include ("_conn/conn_db.php");
$new=$_GET['new'];
if(empty($cart)) $cart=NULL;
if(empty($index)) $index=NULL;
if(empty($new)) $new=NULL;
if($new)
{
if(!session_is_registered('cart')) //session_is_registered('cart')
{
$cart = array();
session_register('cart');
$items = 0;
$total_price = "0.00";
session_register('items');
session_register('total_price');
}
if($cart[$new]) {
$cart[$new]++;
}
else {
$cart[$new]=1; /// ให้ qty เริ่มต้น=1 ใน textbox
$total_price=calculate_price($cart) ;
$items=calculate_items($cart);
}
}// end if($new)
else
{
if($save)
{ echo "มีการเปลี่ยนแปลงจำนวน<br>";
print "<pre>";
print_r($_POST);
print "<pre>";
foreach($cart as $product_id => $qty)
{ echo "$cart as $product_id=>$qty <br>";
if($$product_id=="0")
{ unset($cart[$product_id]);
}
else
{ $cart[$product_id]=$$product_id ;
}
}
$total_price=calculate_price($cart);
$items=calculate_items($cart);
} // end if($save)
}// end else

include ("headshopcart.php");
if($cart&&array_count_values($cart))
{ display_cart($cart,true);

}
else
{ echo "<br></br><center><b> ไม่มีรายการสินค้าในตระกร้า</b></center><br></br><br></br>";
}

?>


////////////////////////
ส่วนของฟังกชันที่ใช้งานคะ
<? function calculate_price($cart)
{
$price=0.0;
if(is_array($cart))
{
include ("_conn/conn_db.php"); //$conn=connect_db("golf");
foreach($cart as $product_id =>$qty)
{ $query="select * from product where p_id='$product_id'";
$result=mysql_query($query);
if($result)
{
$item_price=mysql_result($result,0,"p_price");
$price+=$item_price*$qty;
} // end if
}// end foreach
} //if
return $price;
} // end function calculate_price



function calculate_items($cart)
{ // order Total
$items=0.0;
if(is_array($cart))
{
foreach($cart as $product_id =>$qty)
{
$items+=$qty;
}
}
return $items;
} //end function calculate_items




function display_cart($cart,$change)
{
global $items;
global $total_price;
echo "<form action='show_cart.php' method='post'>
<table width='850' cellspacing='1' bordercolor='#000000' cellspacing='0' align='center'>
<tr align='center' valign='middle' bgcolor='#333333' class='white12'>
<td width='62' class='white12'> Product ID</td>
<td width='138' height='35'>PRODUCT PICTURE</td>
<td width='285'>PRODUCT NAME </td>
<td> PRICE</td>
<td> QUATITY</td>
<td> TOTAL</td>
<td width='81'>&nbsp;</td>
</tr>";
// display product rows
foreach ($cart as $product_id =>$qty)
{ $product=get_product_detail($product_id);
echo " <tr valign='middle' bgcolor='#C0C0C0'>
<td align='center' class='black12'><strong class='black12'>".$product[p_id]."</strong></td>
<td align='center'><a href='p_detail.php?p_id=".$product[p_id]."'><img src='admin/product_images/".$product[p_picname1]."' width='50' height='35' border='0'></a></td>
<td align='center' class='producttopic'><a href='p_detail.php?p_id=".$product[p_id]."'>". $product[p_name]."</a> </td>
<td width='80' align='center' class='red12'>". $product[p_price]."</td>
<td width='80' align='center' class='white11'>";
if($change==true)
{ echo "<input name=\"$product_id\" type='text' size=1 value=$qty>";}
else { echo "<font>".$qty."</font>"; }
echo "</td>";
echo "<td width='80' align='center'><span class='red12'>".number_format($product['p_price']*$qty,2). "</span></td>
<td width='81' align='center'><a href=delete_cart.php?p_id=".$product[p_id]."><img src='admin/images/scissors.png' alt='Delete' border='0'/></a> </td>
</tr>";
} // end foreach
echo "<tr valign='middle' bgcolor='#C0C0C0'>
<td colspan='4' align='center' class='black12'><b>Product in Cart</b></td>
<td width='80' align='center' class='white11'>".$items."</td>
<td width='80' align='center'>".number_format($total_price,2)."</td>
<td width='81' align='center'></td>
</tr>
<tr valign='middle' bgcolor='#000000' class='white11'>
<td colspan='4' align='right'><strong>Total : </strong></td>
<td colspan='3' align='center' bgcolor='#191919'><span class='producttopic'><strong>".number_format($total_price,2)." Bath</strong></span></td>
</tr>
<tr valign='middle' bgcolor='#000000' class='white11'>
<td colspan='4' align='right'><strong>Discount Code : </strong></td>
<td colspan='3' align='center' bgcolor='#191919'><input name='code' type='text' ></td>
</tr>
<tr valign='middle' bgcolor='#000000' class='white11'>
<td colspan='4' align='right'><strong>Merchandise Total : </strong></td>
<td colspan='3' align='center' bgcolor='#191919'>
<input name='discout_code' type='text' value='".number_format(($total_price-($total_price*5/100)),2)."' readonly></td></tr>";
if($change==true)
{ echo "<tr><td colspan='7'><div style='text-align:right; padding-right:100px;'>
<input type='hidden' name='new' value='0'>
<input type='hidden' name='save' value='true'>
<input name='' type='submit' value='บันทึกการเปลี่ยนแปลง'></div></td></tr>";
}
echo "</table></form>";
} // end function display_cart



function get_product_detail($product_id)
{
if(!$product_id || $product_id==''){
return false; }
include ("_conn/conn_db.php");
$sql="select * from product where p_id='$product_id' ";
mysql_query("SET NAMES 'tis620' ");
$query=mysql_query($sql);
if($query=='') {
return false; }
$result=mysql_fetch_array($query);
return $result;
} // // end function get_product_detail;
?>
Date : 2009-10-26 11:47:24 By : nut
 


 

No. 11



โพสกระทู้ ( 1,463 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Blogger

ตัวแปร $$product_id มีค่า null ครับ
เปลี่ยนไปใช้ตัวแปรข้างใน $_POST แทนครับ ลองแล้วใช้ได้แล้วครับ

<?
include ("_include/function.php");
include ("_conn/conn_db.php");

$new=$_GET['new'];
if(empty($cart)) $cart=NULL;
if(empty($index)) $index=NULL;
if(empty($new)) $new=NULL;

if($new)
{
    if(!session_is_registered('cart')) //session_is_registered('cart')
    {
        $cart = array();
        session_register('cart');
        $items = 0;
        $total_price = "0.00";
        session_register('items');
        session_register('total_price');
    }
    if($cart[$new]) {
        $cart[$new]++;
    } else {
        $cart[$new]=1; /// ให้ qty เริ่มต้น=1 ใน textbox
        $total_price=calculate_price($cart) ;
        $items=calculate_items($cart);
    }
}// end if($new)
else
{
    if($save)
    {
        echo "มีการเปลี่ยนแปลงจำนวน<br>";
        print "<pre>";
        print_r($_POST);
        print "<pre>";
        foreach($cart as $product_id => $qty)
        { echo "$cart as $product_id=>$qty <br>";
            $p_qty = $_POST[$product_id];
            if($p_qty == "0")
            { unset($cart[$product_id]);
            }
            else
            { $cart[$product_id] = $p_qty  ;
            }
        }
        $total_price=calculate_price($cart);
        $items=calculate_items($cart);
    } // end if($save)
}// end else

include ("headshopcart.php");
if(!empty($cart))
{
    display_cart($cart,true);
}
else
{ echo "<br></br><center><b> ไม่มีรายการสินค้าในตระกร้า</b></center><br>< /br><br></br>";
}

?>

Date : 2009-10-26 13:17:17 By : num
 


 

No. 12

Guest


ขอบพระคุณมากเลยคะ สรุปคือมันหาค่า $product_id ที่ส่งมาจาก display_cart ไม่เจอ เราต้องทำการรับค่า Post มาก่อนใช่ไหมคะ

โล่งอกไปทีคะ ขอบคุณอีกรอบคะ
Date : 2009-10-26 13:35:12 By : nut
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ทำระบบ shopping cart แล้ว มันเกิด error คือได้ทำระบบ shopping cart แล้ว มันเกิด error
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่