我有下面的嵌套循環。第一個得到manufacturers_name
,並且由於有時在該字段中有多個名稱,我使用第二個foreach循環來拆分數組並獲取每個製造商的ID。問題是循環停在第一個元素$pieces
。PHP foreach循環在爆炸後停止
循環:
foreach ($items as $v) {
$getname = xtc_db_query("SELECT `manufacturers_name` FROM `manufacturers` WHERE `manufacturers_id`=(SELECT manufacturers_id FROM products WHERE products_id='".$v."')");
$getnameresult= xtc_db_fetch_array($getname);
$pieces = explode(";", $getnameresult[manufacturers_name]);
foreach ($pieces as $n)
{
$getid = xtc_db_query("SELECT `manufacturers_id` FROM `authors` WHERE `manufacturers_name` LIKE '".$n."' ");
$getidresult = xtc_db_fetch_array($getid);
echo $getidresult['manufacturers_id'];
echo $n."<br>";
}
}
結果:
2Achtzehn, Hans-Jürgen
2Achtzehn, Hans-Jürgen
2Achtzehn, Hans-Jürgen
2Achtzehn, Hans-Jürgen
2Achtzehn, Hans-Jürgen
2Achtzehn, Hans-Jürgen
228Weisenburger, Birgit
228Weisenburger, Birgit
2Achtzehn, Hans-Jürgen
33Müller, Ulrike
Schmitz, Irmgard
Hampel, Heike
Riedel, Sara
Achtzehn, Hans-Jürgen
Krüger, Andreas
Vogt, Melanie
預期結果:
2Achtzehn, Hans-Jürgen
2Achtzehn, Hans-Jürgen
2Achtzehn, Hans-Jürgen
2Achtzehn, Hans-Jürgen
2Achtzehn, Hans-Jürgen
2Achtzehn, Hans-Jürgen
228Weisenburger, Birgit
228Weisenburger, Birgit
2Achtzehn, Hans-Jürgen
33Müller, Ulrike
56Schmitz, Irmgard
77Hampel, Heike
75Riedel, Sara
34Achtzehn, Hans-Jürgen
65Krüger, Andreas
80Vogt, Melanie