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'];
}
}
答案 0 :(得分: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);