开发者

how to check or select the radio button based from the data from the db table?

am having problem, my app doesn't seem to check the radio button based from the saved data. actually i have two radio buttons, it has a value of 1 or 开发者_运维知识库2 , the saving of the value does work, but when the user visited the app again using his/her account,none of the radio buttons are checked

here's the code for the pulling of data of the radio button from the db table

//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;
       }
}

here's the code for the front-end

$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>

how to fix this ? is there anything wrong with my code ?


Radio buttons use "checked" not "selected"


Do this

 <div align="center" class="radio_group">
        <input type="radio" id="gallerymenustyle1" class="element radio" name="gallerymenustyle[]" value="1" <?php if($checkedgallerymenustyle == 1){ echo "checked=\"yes\""; }?> /> 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 "checked=\"yes\""; }?> /> Category Links - In the navigation of my website, display a separate link to each category.
    </div>

checked="yes"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜