skip to Main Content

i have items, shoes products_tax_class_id =1, bag products_tax_class_id =2, pen products_tax_class_id =3, pencil products_tax_class_id =1 in shopping card.

$result = tep_db_query("select count(*) as tax_check from " . TABLE_PRODUCTS . " where products_tax_class_id = '3' and products_id = '".$items[$i]['id']."'");
while ($get_now = tep_db_fetch_array($result)){
   if ($get_now['tax_check'] > 0) 

if i echo results, prints and returns 0, 0, 1, 0 (i have 4 row) values. i want to see whether is there a 1 value, return of 4 row?

2

Answers


  1. When using SELECT COUNT(*) you should essentially get one row returned. Depending on how large your database is you may want to debug by removing the count() option from the query and do something like:

    while ($get_now = tep_db_fetch_array($result))
    { 
        print_r($get_now)
    }
    

    This will give you an idea where everything comes from.

    Login or Signup to reply.
  2. then i would rather suggest you to change this fetching function to something wich will count rows

    $result = tep_db_query("select * from " . TABLE_PRODUCTS . " where products_tax_class_id = '3' and products_id = '".$items[$i]['id']."'"); 
    $get_now = mysql_num_rows($result); 
    if ($get_now > 0) 
    {
        //we've found it
    }
    else
    {
       //not found
    }
    

    NOTE i used mysql_num_rows because oscommerce doesn’t have a declared function for this

    UPDATED

    if you want to get all products and check if they have tax_class_id = '3' you can fetch them all and then selecting.

    $result = tep_db_query("select * from " . TABLE_PRODUCTS . " where products_id = '".$items[$i]['id']."'"); 
    if($get_now = tep_db_fetch_array($result))
    {
        if ($get_now['products_tax_class_id'] == '3') 
        {
            //this product have class = 3 do something
        }
        else
        {
           //this product haven't class = 3 do something else
        }
    } else {
        //this is just a check for wrong products_id you can avoid this else since products are already in the shopping cart and it's not possible they have wrong products_id
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search