-2

while循环仅适用于该值的第一条记录foreach。我不明白为什么。任何帮助将不胜感激。

foreach($country_array as $country_new)
{ 
    $result=mysql_query("select product.product_id,product.product_name from product left join country_iso_telcode on product.country=country_iso_telcode.country_name left join product_category_listing on product.product_id=product_category_listing.product_id where product.product_name REGEXP '[[:<:]]$search' and country_iso_telcode.region='$region' and product.country='$country_new'")or die("wrong query in search results displaying button results"); 

    while($row=mysql_fetch_array($result)) 
    { 
        $product_id=$row['product_id'];
        $product_name=$row['product_name'];
    }
}
4

1 回答 1

1

基本上你需要把结果放在一个数组中

$arr = array();
foreach($country_array as $country_new)
 { 
     $result=mysql_query("select product.product_id,product.product_name from product left join country_iso_telcode on product.country=country_iso_telcode.country_name left join product_category_listing on product.product_id=product_category_listing.product_id where product.product_name REGEXP '[[:<:]]$search' and country_iso_telcode.region='$region' and product.country='$country_new'")or die("wrong query in search results displaying button results"); 
$i = 0;
while($row=mysql_fetch_array($result)) 
{ 
    $arr[$country_new]['product_id'][$i]=$row['product_id'];
    $arr[$country_new]['product_name'][$i]=$row['product_name'];
    $i++;
}

}
print_r($arr);
于 2013-04-22T11:51:00.083 回答