$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->Category_Term 每次在列表中循环时都是运动。不过,它会正确返回 $row->Category_Label。
这在 Xampp 开发服务器上运行得非常好。然后它被转移到一个 nginx vps 上发布,这个愚蠢的错误出现了。
有什么帮助吗?
最佳答案
您在这里分配给类别而不是比较:
if($row->Category_Term=$category)
在 PHP 中相等是用双等号完成的,所以把它改成:
if($row->Category_Term == $category)
关于php拉取虚假的mysql数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9552307/