选择计数产品

时间:2013-04-15 14:26:26

标签: php shopping-cart oscommerce

我有物品,鞋子products_tax_class_id = 1,bag products_tax_class_id = 2,pen products_tax_class_id = 3,铅笔products_tax_class_id = 1购物卡。

$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) 

如果我回显结果,则打印并返回0,0,1,0(我有4行)值。我想知道是否有1个值,返回4行?

2 个答案:

答案 0 :(得分:0)

使用SELECT COUNT(*)时,基本上应该返回一行。根据您的数据库大小,您可以通过从查询中删除count()选项来调试,并执行以下操作:

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

这会让你知道一切都来自哪里。

答案 1 :(得分:0)

然后我宁愿建议您将此fetching函数更改为将计算行

的内容
$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
}

注意我使用mysql_num_rows,因为oscommerce没有声明的函数

UPDATED

如果您想获取所有产品并检查他们是否有tax_class_id = '3',您可以全部取出然后选择。

$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
}