$query = $this->db->query('SELECT * FROM feeder_categories');
$result = $query->result();
$cat = '';
print $category;
foreach ($result as $row) {
$selected = '';
if($row->Category_Term=$category){$selected = 'selected="1"'; print $row->Category_Term;}
$cat .= "<option value='" . $row->Category_Term . "' ".$selected.">" . $row->Category_Label .
"</option>";
}
数据库看起来像这样(根据phpMyAdmin)
id Category_Term Category_Label
1 Film Film & Animation
2 Autos Autos & Vehicles
3 Music Music
4 Animals Pets & Animals
5 Sports Sports
6 Travel Travel & Events
7 Shortmov Short Movies
8 Videoblog Videoblogging
然而,剧本说$ row-&gt; Category_Term每次循环通过列表都是体育。它正在返回$ row-&gt; Category_Label。
这在Xampp开发服务器上运行得非常好。然后它被移动到nginx vps发布,这个愚蠢的错误出现了。
任何帮助?
答案 0 :(得分:1)
您在此处分配类别而不是比较:
if($row->Category_Term=$category)
在PHP中使用双等于完成平等,因此将其更改为:
if($row->Category_Term == $category)