2016-03-20 62 views
2

我想根據來自mysql表的數據和使用php顯示單選按鈕的列,但我無法在單選按鈕之間切換。以下是代碼。無法在單選按鈕之間切換

   while($rows = $stmt->fetch(PDO::FETCH_ASSOC)){ ?> 
 
        <tr> 
 
\t \t \t \t \t  <td border="0" type="hidden" style="display:none;"><input type="hidden" name="hidden" value=<?php echo $rows['member_id']; ?></td> 
 
         <td class="center"><?php echo $rows['username']; ?></td> 
 
\t \t \t \t \t \t <td class="center"><?php echo $rows['email']; ?></td> 
 
\t \t \t \t \t \t 
 
\t \t \t \t \t \t <?PHP if($_SESSION['user_group'] == 63){ 
 
\t \t \t \t \t \t echo '<td class="center"><input type="radio" id='?><?php echo $rows['username']; 'name="gp" value="system admin"' ?> 
 
\t \t \t \t \t \t  <?php echo ($rows['permission']== 31)?'checked':'' ?>'</input> </td>' <?PHP ; \t \t \t \t \t \t 
 
\t \t \t \t \t \t echo '<td class="center"><input type="radio" id='?><?php echo $rows['username']; 'name="gp" value="admin"' ?> 
 
\t \t \t \t \t \t <?php echo($rows['permission']== 15)?'checked':'' ?> '</input> </td>' <?PHP ; 
 
\t \t \t \t \t \t \t echo '<td class="center"><input type="radio" id='?><?php echo $rows['username'];'name="gp" value="user"' 
 
\t \t \t \t \t \t  ?><?php echo ($rows['permission']== 1)?'checked':'' ?> '</input> </td>' <?PHP ; } 
 
\t \t \t \t 
 
\t \t \t \t \t \t elseif($_SESSION['user_group'] == 31){ \t \t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t echo '<td class="center"><input type="radio" id='?><?php echo $rows['username']; 'name="gp" value="admin"' ?> 
 
\t \t \t \t \t \t <?php echo($rows['permission']== 15)?'checked':'' ?> '</input> </td>' <?PHP ; 
 
\t \t \t \t \t \t \t echo '<td class="center"><input type="radio" id='?><?php echo $rows['username'];'name="gp" value="user"' 
 
\t \t \t \t \t \t  ?><?php echo ($rows['permission']== 1)?'checked':'' ?> '</input> </td>' <?PHP ; } 
 
\t \t \t \t \t \t \t elseif($_SESSION['user_group'] == 15){ \t \t \t \t \t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t echo '<td class="center"><input type="radio" id='?><?php echo $rows['username'];'name="gp" value="user"' 
 
\t \t \t \t \t \t  ?><?php echo ($rows['permission']== 1)?'checked':'' ?> '</input> </td>' <?PHP ; }?> 
 
\t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t \t \t \t \t 
 
         \t <td class="center"><button name="update" type="update">submit</button></td>   
 
          </tr>    
 
        <?php 
 
       }

貌似在代碼中的錯誤。任何幫助。目前的演出情況如下。

enter image description here

我想單選按鈕之間進行切換。

+0

你建立html的方式似乎有點偏離,試着在id和php代碼前添加輸入的名稱和值 – Bart

+0

好的,謝謝你會試試 –

+0

你可以分享在瀏覽器中呈現的html代碼嗎? – itzmukeshy7

回答

0

能夠弄明白。從html列行的開頭刪除回顯命令。代碼如下所示。

while($rows = $stmt->fetch(PDO::FETCH_ASSOC)){ ?> 
 
        <tr> 
 
\t \t \t \t \t  <td border="0" type="hidden" style="display:none;"><input type="hidden" name="hidden" value=<?php echo $rows['member_id']; ?></td> 
 
         <td class="center"><?php echo $rows['username']; ?></td> 
 
\t \t \t \t \t \t <td class="center"><?php echo $rows['email']; ?></td> 
 
\t \t \t \t \t \t 
 
\t \t \t \t \t \t <?PHP if($_SESSION['user_group'] == 63){ ?> 
 
\t \t \t \t \t \t   <td class="center"><input type='radio' id=<?php echo $rows['username']; ?> name="gp" value="system admin" 
 
\t \t \t \t \t \t  <?php echo ($rows['permission']== 31)?'checked':'' ?>></input> </td> 
 
\t \t \t \t \t \t <td class="center"><input type='radio' id=<?php echo $rows['username']; ?> name="gp" value="admin" 
 
\t \t \t \t \t \t  <?php echo ($rows['permission']== 15)?'checked':'' ?> ></input> </td> 
 
\t \t \t \t \t \t \t <td class="center"><input type='radio' id=<?php echo $rows['username']; ?> name="gp" value="user" 
 
\t \t \t \t \t \t  <?php echo ($rows['permission']== 1)?'checked':'' ?> ></input> </td> <?PHP } 
 
\t \t \t \t 
 
\t \t \t \t \t \t elseif($_SESSION['user_group'] == 31){ ?> \t \t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t <td class="center"><input type='radio' id=<?php echo $rows['username']; ?> name="gp" value="admin" 
 
\t \t \t \t \t \t  <?php echo ($rows['permission']== 15)?'checked':'' ?> ></input> </td> 
 
\t \t \t \t \t \t \t <td class="center"><input type='radio' id=<?php echo $rows['username']; ?> name="gp" value="user" 
 
\t \t \t \t \t \t  <?php echo ($rows['permission']== 1)?'checked':'' ?> ></input> </td> <?PHP } 
 
\t \t \t \t \t \t \t elseif($_SESSION['user_group'] == 15){ \t ?> \t \t \t \t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t <td class="center"><input type='radio' id=<?php echo $rows['username']; ?> name="gp" value="user" 
 
\t \t \t \t \t \t  <?php echo ($rows['permission']== 1)?'checked':'' ?> ></input> </td><?PHP }?> 
 
\t \t \t \t

這工作就好了。