views:

26

answers:

1

Hello,

I do have a little expierence with database tables, but I can't read a db_query I believe to have a query which should enable a product as a bestseller and place it in scroller. I want to fake a bestseller because it looks a little dump when opening a webshop with having a empty bestseller list.

I have manually altered the table "products_ordered" and altered a products column to 3 (like the product is ordered 3 times) still nothing happends in the scroller. What should I do next?

What am I doing wrong?

This is the query:

$best_sellers_scroll_query = tep_db_query("select distinct p.products_id, 
pd.products_description, p.products_image, p.products_price, 
p.products_tax_class_id, pd.products_name from " .              
TABLE_PRODUCTS . " p, " . 
    TABLE_PRODUCTS_DESCRIPTION . " pd, " . 
    TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . 
    TABLE_CATEGORIES . " c where p.products_status = '1' and 
p.products_ordered > 0 and p.products_id = pd.products_id and 
pd.language_id = '" . 
    (int)$languages_id . "' and p.products_id = p2c.products_id and 
p2c.categories_id = c.categories_id and '" . 
    (int)$current_category_id . "' in (c.categories_id, c.parent_id) 
order by p.products_ordered desc, pd.products_name limit " . 
MAX_DISPLAY_BESTSELLERS_SLIDER);

This is the slider.js

  var prepare_slider = function(x_cols, x_dur){

      var x_pos = 0;
      var li_items_n = 0;   
      var li_col = $('slider_list').getElements('li');

      li_col.each(function(li, index){
          size = li.getSize();
          x_pos += size.x;
          li_items_n++;
      })

      $('slider_list').setStyle('position','relative');
      $('slider_list').setStyle('left','0px');
      $('slider_list').setStyle('width', x_pos+'px');
      /*  alert("The element is "+size.x);  */

      var myFx = new Fx.Tween($('slider_list'), {transition: 
Fx.Transitions.Sine.easeOut, duration:x_dur});
      myFx.addEvent('start', function(){ is_playing = true; });
      myFx.addEvent('complete', function(){ is_playing = false; });

      var is_playing = false;

      $('left').addEvent('click', function(){
          cur_offset = $('slider_list').getStyle('left').toInt();
          if (!is_playing && ((cur_offset + size.x) <= 0)) 
myFx.start('left',   cur_offset + size.x + 'px');
      });

      $('right').addEvent('click', function(){
          var is_playing = false;
          cur_offset = $('slider_list').getStyle('left').toInt();
          if (!is_playing && ((cur_offset - size.x) 
>= (x_cols*size.x-x_pos) )) myFx.start('left', cur_offset - size.x + 'px'); 
      });   
  }

Outcome of the dump:

string(179) "4' and p.products_id = p2c.products_id 
and p2c.categories_id = c.categories_id and '0' in (c.categories_id, 
c.parent_id) order by p.products_ordered desc, 
pd.products_name limit 1" 1064 - 
You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to 
use near ''0' at line 1

select distinct p.products_id, pd.products_description, 
p.products_image, p.products_price, p.products_tax_class_id, 
pd.products_name from products p, products_description pd, 
products_to_categories p2c, categories c where 
p.products_status = '1' and p.products_ordered > 0 and 
p.products_id = pd.products_id and pd.language_id = '0

[TEP STOP]
A: 

You have to check why no products are found by the query:

  • Find out which product it was where you altered the products_ordered column (look for products_id)
  • Check if that product has products_status = 1
  • Check if there is an entry in table products_description which has the same products_id and a language_id of your current language (do a var_dump($languages_id))
  • Check if there is an entry in table products_to_categories which has the same products_id and a categories_id of your current category (do a var_dump($current_category_id))
  • Check if that category exists in table categories
  • Check if MAX_DISPLAY_BESTSELLERS_SLIDER > 0

  • Check if your slider works by replacing the "WHERE " with "WHERE TRUE OR "

AndreKR
Product_id: 8545, status 1: yes, products_description, yes, same language_id: 4 (ps. how do i perform a var_dump($languages_id)) product_to_categories has product_id 8545 and categories_id 186. categorie 186 excists (no categorie image though)
Chris
The var_dumps need to be put into the PHP code, right where you copied the Query from above. Just insert "var_dump(...);" after the "MAX_DISPLAY_BESTSELLERS_SLIDER);"
AndreKR
I don't have a clue what you mean.
Chris
ok, i think i figured it out, this is the outcome. I have edited the question with the outcome.
Chris