0

我在购物卡中有物品,鞋子 products_tax_class_id =1,包 products_tax_class_id =2,笔 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 行?

4

2 回答 2

0

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

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

这将使您了解所有内容的来源。

于 2013-04-15T14:43:23.280 回答
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
}
于 2013-04-15T14:43:30.550 回答