2013-04-22 105 views
-2

while loop仅适用于foreach值的第一条记录。我无法理解为什么。任何帮助将不胜感激。while foreach while while in php does not work

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']; 
    } 
} 
+3

您有这方面再次询问现在,删除你刚才的问题.. – 2013-04-22 11:46:25

+0

你不能强迫任何人回答或一再提出的问题以刺激他们.. – 2013-04-22 11:53:07

+0

为什么我的问题会刺激任何人?我不是在这里强迫任何人..我以前的帖子被关闭,并成为一个垃圾无尽的答复。我还能做些什么@Coder – Sha 2013-04-22 12:14:34

回答

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); 
+1

啊谢谢你soooooooooooo ....你从更多的想法中拯救了我:) @Chandresh – Sha 2013-04-22 12:11:22

+0

@ user2294969干杯和快乐编码:) – 2013-04-22 12:12:02