Jump to content

acsonline

Members
  • Posts

    41
  • Joined

  • Last visited

    Never

Everything posted by acsonline

  1. Wow - that works thank you... Now, is there a similar way to dump all items in to the basket at once? echo $value .' x '. $product->name .' @ £'. $product->price .'<br>'; echo wpsc_add_to_cart_button($product->id) . '<br>'; This code lists one button per product - but I also tried an add all button...
  2. Hey, I just ran the system now, and got this: Cannot use object of type stdClass as array in Any ideas?
  3. Ah, Well now I realise there is an extra table to check... The SKU is meta_sku in the productmeta table.... then that is passed over to the product_list table using product ID.... I tried the first sql you wrote and that displayed 2x@ etc.. tried the newest sql but had an error show up..
  4. Bingo!! All I need to know is the product ID, product name and price, so that I can display them.... Then I can create a buy now button using the shortcode and the product id (Then I need to work out a way to add quantity too....)
  5. Hi, It is indeed the SKU, I'm using a totally independent code, hand written - basically this is a food shop and there is a recipes section. On that post it needs to show the food items needed to make that recipes.... So in the posts section, I have custom fields installed, which allows me to enter the food items needed... i.e: FRE0001,FRE0009,FRE0009,FRE0024 - Notice there are 2 x FRE0009 so on the shopping list it would show 1 x PRODUCT 1 @ 29p, 2 x PRODUCT 9 @5.60 and 1 x PRODUCT 24 @69p I hope this helps clarify it a little better
  6. Hey, Its WP E-Commerce, so if I used something like: <?php $where = 'WHERE id = $productid'; $sql = 'SELECT DISTINCT ' . ENTRY_TABLE . '.* FROM ' . ENTRY_TABLE . ' ' . implode(' ', $join) . ' ' . implode(' ', $where) . ' ' . 'ORDER BY `product_id`; $results = $wpdb->get_results($sql); foreach($results as $result) { echo $result['product_id']; } ?> However what do I do for $join - and I'm assuming that i replace ENTRY_TABLE with wordpdem_wpsc_product_list
  7. hmmm, Ok, further to that, I found this page: http://wordpress.org/support/topic/how-to-query-database which shows a query: $pageposts = $wpdb->get_results($sql, ARRAY_N); while($row = mysql_fetch_array($pageposts)) { echo $row['fieldname']; } So I changed to: foreach ($products as $key => $value) { $sql = "SELECT product_id FROM wordpdem_wpsc_productmeta WHERE meta_value = '$key'"; $productid = $wpdb->get_results($sql, ARRAY_N); echo $sql . "<br>"; //THIS ECHO CORRECTLY } while($row = mysql_fetch_array($productid)) { echo $row['product_id']; //NOW GET AN ERROR Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in XXXXXX/comments.php on line 18 } Any ideas why this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in XXXXXX/comments.php on line 18 comes up?
  8. I ran an echo on my sql to check the code and it appears to be working correctly. SELECT product_id FROM wordpdem_wpsc_productmeta WHERE meta_value = 'FRE0001' SELECT product_id FROM wordpdem_wpsc_productmeta WHERE meta_value = 'FRE0009' SELECT product_id FROM wordpdem_wpsc_productmeta WHERE meta_value = 'FRE0024' this is the code now <?php if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) die ('Please do not load this page directly. Thanks!'); if (is_page()) { } else { $key="Linked Products"; $idcode= get_post_meta($post->ID, $key, true); $array = explode(",",$idcode); $products = array_count_values($array); foreach ($products as $key => $value) { $sql = "SELECT product_id FROM wordpdem_wpsc_productmeta WHERE meta_value = '$key'"; $productid = $wpdb->get_results($sql); echo $sql . "<br>"; } // foreach ($productid as $prod_id) { // echo $prod_id; // $product = $wpdb->get_results( "SELECT name, price FROM wordpdem_wpsc_product_list WHERE id = '$productid'" ); // } $pid = '376'; ?> <span class="art-button-wrapper"> <span class="l"> </span> <span class="r"> </span> <?php wpsc_add_to_cart_button($pid); ?> </form></span> <?php } ?> Any ideas how I can get the next stage? I've commented out the code that fails... how can I get the data? Thank You
  9. basically there is an online store in use, which for some reason splits the product code to one table and the name and price to a different table. we then have a section of posts - and we add product references to the pages, i.e. relevant products... on the post page, we have text then a section that says: "To do this you will need...." and then the list of products (and a link to buy now button) when we create the post we have custom fields which we input the relevant items in to... FRE0001,FRE0009 etc, and it we need 2 of something we simply put it in twice... FRE0001,FRE0009,FRE0009 etc.... So we need to check that field - find out what is required... $key="Linked Products"; $idcode= get_post_meta($post->ID, $key, true); $array = explode(",",$idcode); $products = array_count_values($array); at present this would display FRE0009 - 2, FRE0001 etc etc... so now we know the codes, we can query the DB for the product id, and then check the table for the name and price...
  10. Hey, I have one DB with 2 tables, one table has the product details, and the other has codes - So I need to reference the table wordpdem_wpsc_productmeta and get the product_id where meta_value = "FRE0009" etc... then check to get the name and price of FRE0009 from the table wordpdem_wpsc_product_list. The output I need from thsi whole query is - Ref (FRE0009), Name, price and Quantity (How many times FRE0009 is in the first list) So Far, I have got the reference using the code: $idcode= get_post_meta($post->ID, $key, true); $array = explode(",",$idcode); $products = array_count_values($array); So now I need to count the different times the codes are outputted, then check the other DB for Name and Price...
  11. Ah ha, Excellent thank you!!! I've got it reading the array now, however I'm now strugling to connect to the wordpress system... This is my code: <?php if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) die ('Please do not load this page directly. Thanks!'); if (is_page()) { } else { $key="Linked Products"; $idcode= get_post_meta($post->ID, $key, true); $array = explode(",",$idcode); $products = array_count_values($array); foreach ($products as $key => $value) { $productid = $wpdb->get_results( "SELECT product_id FROM wordpdem_wpsc_productmeta WHERE meta_value = '$key'" ); } } ?> I tried to echo $productid but it just says array..... I need it to tell me the product_id from the database... Any ideas
  12. Ok, thanks guys, getting closer now $array = explode(",",$products); $products = array_count_values($array); print_r(array_values($array)); print_r(array_keys($products)); foreach ($products as $value => $key){ echo $products . "<br>"; but I just get array array array instead of the code - plus how can I find out the quantity in the array too?
  13. hey, I've been looking at that but how do I get just the data out of the code, rather than the full array too? I need to just get FRE0009 etc.... rather than the whole array code
  14. I've now added this: $array = explode(",",$products); $products = array_count_values($array); print_r($products); which now displays this: Array ( [FRE0001] => 1 [FRE0009] => 2 [FRE0024] => 2 ) How do I get use the id? (FRE0001) etc....
  15. Hey, I am trying to make and then read an array of items. Can someone help please? I have a database field that holds an unlimited number of codes, and I need to get those codes.... at the moment I have a section of php $products= array($products); $array = array_values($products); print_r($array); which generates Array ( [0] => FRE0001,FRE0009,FRE0009,FRE0024,FRE0024 ) as the output... What I need is to know how many of each code there are and the different codes.... i.e. 1 x FRE0001, 2 x FRE0009, 2 x FRE0024 Whats the best way to output the array and then count?
  16. Hey Guys, I have a wordpress site, and there are custom fields in use. I can use <?php get_post_meta($key); ?> I need to count the output - for example on the page it may say FLO001,FLO001,FLO001,FLO004,FLO065 So I would need to know 3 x FLO001, 1 x FLO004, 1 x FLO065 Then check the database to find out the details for those codes. I need to explode the array, then count then query - but how can I do this?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.