【发布时间】:2011-08-26 20:17:31
【问题描述】:
我遇到了问题,我的应用似乎没有根据保存的数据检查单选按钮。实际上我有两个单选按钮,它的值为 1 或 2 ,值的保存确实有效,但是当用户使用他/她的帐户再次访问该应用程序时,没有选中任何单选按钮
这是从 db 表中提取单选按钮数据的代码
//User.php
public function getGalleryMenuStyle($id = ''){
$gallerymenustyle = "SELECT gallery_menu_style FROM users WHERE user_id = ".$id;
$this->dbSelectQuery = $gallerymenustyle;
$checkedgallerymenustyle = $this->userDBSelect();
if($checkedgallerymenustyle){
return $checkedgallerymenustyle;
} else {
return false;
}
}
这是前端的代码
$userCats = new User();
$user_id = $_SESSION['userData']['user_id'];
$checkedgallerymenustyle = $userCats->getGalleryMenuStyle($user_id);
<div align="center" class="radio_group">
<input type="radio" id="gallerymenustyle1" class="element radio" name="gallerymenustyle[]" value="1" <?php if($checkedgallerymenustyle == 1){ echo "selected"; }?> /> Gallery Link - In the navigation of my website, display one "gallery" link<br />
<input type="radio" id="gallerymenustyle2" class="element radio" name="gallerymenustyle[]" value="2" <?php if($checkedgallerymenustyle == 2){ echo "selected"; }?> /> Category Links - In the navigation of my website, display a separate link to each category.
</div>
如何解决这个问题?我的代码有什么问题吗?
【问题讨论】:
-
您是否尝试在前端回显
$checkedgallerymenustyle以查看您是否获得了正确的值? -
好的,所以不要使用echo,试试
print_r($checkedgallerymenustyle);,这将显示你的数组中有什么,你可以看看它们是否有你需要的值。