【发布时间】:2014-10-19 19:26:28
【问题描述】:
这行$find_cond = str_replace('|',' ',$rem_exp); 返回 225 和 245 数字。
我想根据这两个 id 号获取记录。但是下面的代码重复返回输出。
如何正确地将 while 循环代码放入 foreach 中?
foreach($arr_val as $key => $val)
{
$c_subsubtopic = str_replace('-','_',$subsubtopic);
$rem_exp = $val[$c_subsubtopic];
$find_cond = str_replace('|',' ',$rem_exp);
$sql = "SELECT a.item_id, a.item_name, a.item_url, b.value_url, b.value_name, b.value_id FROM ".TBL_CARSPEC_ITEMS." a, ".TBL_CARSPEC_VALUES." b WHERE a.item_id = b.item_id AND a.item_url = '".$subsubtopic."' AND value_id = '".$find_cond."' AND a.status = '1'";
while($r = mysql_fetch_array(mysql_query($sql)))
{
echo $r['value_name'];
}
}
【问题讨论】:
-
建议先打印$sql,运行sql查看结果。
-
就像他说的。首先提取您的数据集。然后针对它运行你的 while 语句。
标签: php mysql arrays foreach while-loop