我在下面描述的while循环..My问题中有问题。
$sql = mysql_query($query, $this->db);
if(mysql_num_rows($sql) > 0)
{
$result = array();
while($rlt = mysql_fetch_array($sql,MYSQL_ASSOC))
{
$theature = explode(",",$rlt['mw_movie_theature']);
//echo 'count'.count($theature).'<br/>'; print_r($theature);
for($i = 0; $i<count($theature); $i++ )
{
$sqls = mysql_query("SELECT * FROM mw_theatres WHERE status = 1 AND id='".$theature[$i]."'", $this->db);
$rlts = array();
while($rlts = mysql_fetch_array($sqls,MYSQL_ASSOC))
{
$rlt['movie'] = $rlts;
}
}
$rlt['value'] = 'true';
$result[] = $rlt;
}
echo '<pre>';print_r($result);die;具有2,3,4值的$theature变量。但是$rlt‘’movie‘的值只给出了最后4个id结果。我想要2,3,4个id值。
发布于 2013-07-25 13:24:09
你应该试试这个:--
$sqls = mysql_query("SELECT * FROM mw_theatres WHERE status = 1 AND id='".$theature[$i]."'", $this->db);
$rlts = array();
$j=0;
while($rlts = mysql_fetch_array($sqls,MYSQL_ASSOC))
{
$rlt['movie'][$j] = $rlts;
$j++;
}发布于 2013-07-25 13:19:08
因为每次您将$rlts赋给相同的变量$rlt‘’movie‘。尝试$rlt‘’movie‘
发布于 2013-12-25 14:19:08
$sqls = mysql_query("SELECT * FROM mw_theatres WHERE status = 1 AND id IN (".$theature.")", $this->db);
$rlts = array();
$k = 0;
while($rlts = mysql_fetch_array($sqls,MYSQL_ASSOC))
{
$rlt['movie'][$k] = $rlts;
$k++;
}在where类中,我们使用id In,它只检查变量中作为字符串的id,因此没有使用额外的for循环和explod函数
https://stackoverflow.com/questions/17849535
复制相似问题