有人可以帮助我,因为我是php新手吗?
我正在运行一个电影网站,该网站使用smarty模板引擎,我想做的是返回并显示每部电影的所有类别,但是发生的事情是,当我使用此功能时,它对所有电影都显示相同的类别“喜剧”
功能
public function getByPerma($perma, $lang=null){
$perma = mysql_real_escape_string($perma);
$movie = array();
$e = mysql_query("SELECT * FROM movies WHERE perma='$perma'") or die(mysql_error());
if (mysql_num_rows($e)>0){
$movie = $this->formatMovieData(mysql_fetch_assoc($e), $lang);
}
return $movie;
}
public function getMovieCategoryDetails($movieid,$lang=null){
$movieid = mysql_real_escape_string($movieid);
$e = mysql_query("SELECT * FROM movie_tags WHERE id IN (SELECT tag_id FROM movie_tags_join WHERE movie_id=$movieid)") or die(mysql_error());
$tags = array();
if (mysql_num_rows($e)){
while($s = mysql_fetch_array($e)){
$s['tag'] = json_decode($s['tag'],true);
if ($lang){
$s['tag'] = $s['tag'][$lang];
}
$tags[$s['id']] = $s;
}
}
return $tags;
}
称为功能
$movies = $movie->getByPerma($perma,$language);
if (empty($movies)) {
$movies = '';
} else {
$tags = $movie->getMovieCategoryDetails($movies['id'],$language);
if (!count($tags)){
$smarty->assign("tags","");
} else {
$smarty->assign("tags",$tags);
}
}
并显示类别
{foreach from=$tags key=id item=val name=tags}
{$val.tag}
{/foreach}
我希望有人能帮帮忙?
最佳答案
我认为您的getByPerma()仅返回1个电影信息,当将项目添加到数组时,缺少[]:
$movie = $this->formatMovieData(mysql_fetch_assoc($e), $lang);
-->
$movie[] = $this->formatMovieData(mysql_fetch_assoc($e), $lang);
关于php - 只退回1项,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20261492/