php - 编辑表中的两列

标签 php jquery mysql twitter-bootstrap

我正在制作一个网站,他们想在其中编辑一个包含两列的表格,

我已经遵循了本教程(下面的链接)

http://www.jqueryajaxphp.com/live-table-edit-using-jquery-ajax-and-php-twitter-bootstrap/

我可以让一列工作正常,它编辑并保存回数据库,我无法让第二个编辑。

我已将其包含在内以便人们可以在网站上看到表格,但给他们一个管理页面以便他可以编辑。

http://www.medinaswindon.co.uk/med/admin/

我需要使列上的内容可编辑并可保存到数据库,

我使用的代码是

<?php
include("connect.php");
?>

    <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="assets/css/custom.css" rel="stylesheet" type="text/css">


    <div class="container">
      <div class="row">
          <table class= "table table-striped table-bordered table-hover">
                        <thead>
                            <tr>


                            <th colspan="1" rowspan="1" style="width: 180px;" tabindex="0">DAY /     DATE</th>

                            <th colspan="1" rowspan="1" style="width: 220px;"          tabindex="0">WHAT’S ON</th>

                            <th colspan="1" rowspan="1" style="width: 288px;" tabindex="0">Status</th>
                        </tr>
                    </thead>

                    <tbody>
                    <?php
                    $query = mysql_query("select * from information");
                    $i=0;
                    while($fetch = mysql_fetch_array($query))
                    {
                        if($i%2==0) $class = 'even'; else $class = 'odd';

                        echo'<tr class="'.$class.'">

                            <td><span class= "xedit" id="'.$fetch['id'].'">'.$fetch['name'].'</span></td>

                            <td>'.$fetch['details'].'</td>

                            <td>'.$fetch['status'].'</td>
                        </tr>';                         
                    }
                    ?>
                    </tbody>
    </table>

有什么想法吗?

最佳答案

尝试改变这部分:

<td><span class= "xedit" id="'.$fetch['id'].'">'.$fetch['name'].'</span></td>
<td>'.$fetch['details'].'</td>
<td>'.$fetch['status'].'</td>

对此:

<td><span class= "xedit" id="n'.$fetch['id'].'">'.$fetch['name'].'</span></td>
<td><span class= "xedit" id="d'.$fetch['id'].'">'.$fetch['details'].'</span></td>
<td>'.$fetch['status'].'</td>

这应该也使详细信息字段可编辑,然后您可以进入您的 PHP 代码并根据 id 提交数据。

我没有看到用于保存信息的 PHP 代码,但这应该说明了如何根据名称或详细信息字段对信息进行排序:

if($_GET['id'] and $_GET['data']) { 
    $type = substr($_GET['id'],0,1);
    $id = substr($_GET['id'],1);
    $data = $_GET['data']; 
    if ($type == 'n')
        mysql_query("update information set name='$data' where id='$id'");
    if ($type == 'd')
        mysql_query("update information set details='$data' where id='$id'");
} ?>   

在旁注中,您应该避免使用 mysql_query 函数,因为它已被弃用,请查看 MysqliPDO

关于php - 编辑表中的两列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27089291/

相关文章:

php - 在 1and1 托管中发送邮件时遇到问题

javascript - 如果未选择 radio ,则使用 jquery 隐藏加载的 div

mysql - 不使用子查询计算具有特定状态的行的出现次数

mysql - 使用zymichost创建表

php - Laravel 5.1 在表单请求验证之前修改输入

php - cURL 返回空白

php - 我想从我的网站简单地重定向到某个网址,而无需刷新 session

php - ckeditor 与 jquery 更改事件

JQuery 滑动效果不起作用?

php - 无法以管理员权限访问mysql数据库