dongshimao7115 2015-10-22 11:12
浏览 42
已采纳

如何通过单击切换显示的数据库字段

I have a database table and one specific value is either a value of Yes or No represented by an icon of checkmark or X.

database display

I want to be able to toggle this value with a single click rather then the current workflow where the user clicks the icon and then they are directed to update page where they toggle the value and then update.

current update page

The value is either Yes or No. I simply want to click it have the value change to the opposite value real time without refreshing. Thank you

Here is the partial code for the display database, the field name is called 'enter'

<?php
include "db.inc.php";

if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; }; 
$start_from = ($page-1) * 15; 
$sql = "SELECT * FROM ircb ORDER BY id DESC LIMIT $start_from, 15";

$rs_result = mysql_query ($sql);
$num_rows = mysql_num_rows($rs_result);
$query = mysql_query("SELECT * FROM ircb"); 
$number=mysql_num_rows($query);

while($rows=mysql_fetch_array($rs_result)){ 

<tr bgcolor='#9B9D9F'>
<td><?= $rows['totalt'] ?></td>
       <td><?= $rows['service'] ?></td>
       <td><?= $rows['item'] ?></td>
       <td align="center">
           <a href="edit_form1.php?id=<?= $rows['id'] ?>">
               <img src="backgrounds/bg/<?= $rows['enter'] ?>.png"     border="0">
           </a>
       </td>
</tr>

The edit.form1

  <form method="post" action="update1.php">
  <input type="hidden" name="id" value=<?php echo "$row[id]"?>">


   <tr>
      <td>Entered</td>
      <td>
        <input type="radio" name="enter"  
      value=Yes>Yes<input type="radio" name="enter" value=No checked>No
      </td>
    </tr>
   <hr />
    <tr style="height: 20px"><td></td></tr>
    <tr> 

      <td align="right">
        <input class="button" type="submit" 
       value="Update">
      </td>
  • 写回答

1条回答 默认 最新

  • douzizang7783 2015-10-22 11:43
    关注

    The problem you are having seems to be because you are redirecting to a page that has a form to do the update. Instead of using a form, you could use the link directly to do the trick. The best way to do it is to have the href lead to the exact same page that displays the table, but adding query parameters to tell the scripts to toggle the required row.

    <a href="MY_TABLE.php?toggle_id=<?= $rows['id'] ?>"></a>
    

    Using this, you could check in your PHP, before querying the database to display the tables:

    if($_GET['toggle_id']){
        //$_GET['toggle_id'] = the ID of the line to modify
        //Use the same script as the form handler
    }
    

    So instead of waiting for a value of YES or NO, you would figure it out yourself using the current value:

     $nextValue = $currentValue=='NO'?'YES':'NO';
    

    That should cover most of the logic.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥15 如何修改pca中的feature函数
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况