从管理员批准后更新数据库

时间:2016-07-14 12:35:57

标签: javascript php jquery mysql ajax

`我有一个显示推荐书的网页。我想只显示数据库中“状态”为“1”的推荐。管理员点击更新后,如何立即将名为“status”的数据库列从“0”更新为“1”。我也在使用AJAX。

<tr align='center'>
<?php
include ('includes/connect.php');
$query1= "SELECT* from testdata ORDER BY 1  DESC ";
                                         $run= mysql_query($query1) ;

                                         while 
                                            ($row =mysql_fetch_array($run)){

                                                $Id=$row['0'];
                                                $name=$row['1'];
                                                $company=$row['2'];
                                                $designation=$row['3'];
                                                $email= $row['4'];
                                                $message=$row['5'];




                                       ?>

<td> <?php echo $Id?>  </td>
<td> <?php echo $name; ?> </td>
<td> <?php echo $company ?> </td>
<td> <?php echo $designation ?> </td>
<td> <?php echo $email ?> </td>
<td> <?php echo $message ?> </td>


<td > <form method ="post" action= "update.php"> <input type ="submit" value= "approve" name ="approve"></input></form>  </td>
</tr>

<?php } ?>
















<tr align='center'>
<td> <?php echo $Id?>  </td>
<td> <?php echo $name1; ?> </td>
<td> <?php echo $company1 ?> </td>
<td> <?php echo $designation1 ?> </td>
<td> <?php echo $email1 ?> </td>
<td> <?php echo $message1 ?> </td>


<td > <input class='action' type ="submit" value= "update" name ="update"></input> </td>
</tr>
   

1 个答案:

答案 0 :(得分:0)

只需更改您的查询

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-3 col-xs-6">
      col1
    </div>
    <div class="col-sm-3 col-xs-6">
      col2
    </div>
    <div class="col-sm-3 col-xs-6">
      col3
    </div>
    <div class="col-sm-3 col-xs-6">
      col4
    </div>
  </div>
</div>

并在您的脚本中将$(this).attr(&#39; id&#39;)更改为$(this).val()

"select * from testdata where status =".$_POST['data1'] "