[英]PHP while loops with for loops trouble
编辑:知道了,简直不敢相信我错过了-
$ HTTP_POST_VARS不是全局的,将其更改为要传入的参数。
我通常使用$ _POST,但是在oscommerce中,默认值是这个,因此我使用它来保持相似性。
我无法使此代码正常工作,我也不知道为什么。
function check_product_available() {
global $cart;
$products = $cart->get_products();
//product exclusion
//check to see if the product is in one of the limited categories
$check_product_query = tep_db_query( $sql = 'SELECT products_id
FROM discount_coupons_to_products
WHERE coupons_id="'.tep_db_input( $HTTP_POST_VARS['couponcart'] ).'"' );
$exlproducts = array();
if( tep_db_num_rows( $check_product_query ) > 0 ) {
while( $products = tep_db_fetch_array( $check_product_query ) ) {
$exlproducts[] = $products['products_id'];
}
}
for ($i=0, $n=sizeof($products); $i<$n; $i++) {
if( in_array( $products[$i]['id'], $exlproducts ) ) {
//use this to debug exclusions:
return false;
}
}
return true;
}
//end product exclusion
我尝试过移动循环,但仍然始终返回true。 我已经回显了产品数组,并且id在其中,并运行了对优惠券ID进行硬编码的sql查询,它也可以正常工作。
您的for循环没有意义,因为它只会循环一次。 返回值将结束所有其他执行。 您可能想要的是在数组中返回false,而在其他所有条件下返回true。
for ($i=0, $n=sizeof($products); $i<$n; $i++) {
if( in_array( $products[$i]['id'], $exlproducts ) ) {
//use this to debug exclusions:
return false;
}
}
return true;
编辑:您真的不应该再使用$HTTP_POST_VARS
了。
得到它了....
$ HTTP_POST_VARS不是全局的,将其更改为要传入的参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.