2013-04-22 76 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