Hi Guys im using array_count_values($cart) to try and count the values in an array and get the following error Warning: array_count_values() [function.array-count-values]: Can only count STRING and INTEGER values! in C:\Users\htdocs\projectBookstore\show_cart.php on line 48 the contents are titles of books so i thought they would be strings anyone have any idea how to solve, or use a toString method on the array contents NOT to turn the entire array to one string but serperate strings... Cheers Guys
nah mte it didnt work what im doing is creating a bookstore adding books to a cart and then when purchasing a book allowing the user to change the qty of books..it works fine for qty of 1 but when i go to change qty it errors..anyways thanks for your help i know its hard when you havent got the code in front of you cheers Ian
Hm, not sure why you need array_count_values() then. Wouldn't be something like this easier? $title = 'The Lemur'; $quantity = 1; if (isset($cart[$title])) { $cart[$title] += $quantity; } else { $cart[$title] = $quantity; } PHP: ??
<? include (functions.php'); // The shopping cart needs sessions, so start one session_start(); if($new) { //new item selected if(!session_is_registered("cart")) { $cart = array(); session_register("cart"); $items = 0; session_register("items"); $total_price = "0.00"; session_register("total_price"); } if($cart[$new]) $cart[$new]++; else $cart[$new] = 1; $total_price = calculate_price($cart); $items = calculate_items($cart); } if($save) { foreach ($cart as $isbn => $qty) { if($$isbn=="0") unset($cart[$isbn]); else $cart[$isbn] = $$isbn; } $total_price = calculate_price($cart); $items = calculate_items($cart); } do_html_header("Your shopping cart"); if($cart&&array_count_values($cart)) display_cart($cart); else { echo "<p>There are no items in your cart"; echo "<hr>"; } $target = "index.php"; // if we have just added an item to the cart, continue shopping in that category if($new) { $details = get_book_details($new); if($details["catid"]) $target = "show_cat.php?catid=".$details["catid"]; } display_button($target, "continue-shopping", "Continue Shopping"); $path = $PHP_SELF; $path = str_replace("show_cart.php", "", $path); display_button("https://".$SERVER_NAME.$path."checkout.php", "go-to-checkout", "Go To Checkout"); do_html_footer(); ?> thats a part of the code mate the error happens when i click save, iv been making this myself and looking at a book for parts of it so its a mixture of both. basically when i click save (which is save changes to the qty input box) i want it to take the new value as qty thats when i get the ERROR Cheers dude