【问题标题】:Select data from 2 mysql tables in Jquery EasyUI在 Jquery EasyUI 中从 2 个 mysql 表中选择数据
【发布时间】:2014-05-07 04:19:31
【问题描述】:

您好,我是使用 jquery easyui 的新手。 我创建了 3 个文件,project.php、projectdetail.php 和 get_project_detail.php
这是我的 project.php

代码
...
...
<table id="dg" title="Next Target" class="easyui-datagrid" style="width:700px;height:automatic" 
            url="get_project_nt.php"
            pagination="true"
            rownumbers="true"
            fitColumns="true"
            singleSelect="true">
        <thead>
            <tr>
                <th formatter="formatProjectId" width="165" sortable="true" field="projectname">Project Name</th>
                <th width="100" sortable="true" field="target">Target End Of 2014</th>
                <th width="100" sortable="true" field="PIC">PIC</th>
                <th width="75" sortable="true" field="begindate">Begin</th>
                <th width="75" sortable="true" field="enddate">End</th>
                <th formatter="formatProgress" width="150" sortable="true" field="progress">Progress</th>
            </tr>
        </thead>
    </table>
...
...
<script type="text/javascript">
    function formatProjectId(val,row){
    var url = "projectdetail.php?id=";
    return '<a href="'+url + row.projectname+'">'+val+'</a>';
    }
    </script>

我使用 formatter ="formatProjectId" 将 id 值扔到文件 projectdetail.php

这是文件projectdetail.php

...
...
<?
include 'conn.php';
$query = "SELECT * FROM project WHERE projectname ='".$_GET['id']."'";
$hasil = mysql_query($query);
while ($data = mysql_fetch_array($hasil))
{
   echo"<table>";
   echo "<tr><td>Nama project</td> <td>:</td><td>$data[projectname]</td></tr>";
   echo "<tr><td>Target End of</td> <td>:</td><td>$data[target]</td></tr>";
   echo "<tr><td>Last Update</td> <td>:</td><td>$data[lastupdate]</td></tr>";
   echo"</table>";
    ?>
</table>
    <table id="dg" title="All Project" class="easyui-datagrid" style="width:automatic;height:automatic" 
            url="get_project_detail.php"
            toolbar="#toolbar" 
            pagination="true"
            rownumbers="true"
            fitColumns="true"
            singleSelect="true">
        <thead>
            <tr>
                <th width="165" sortable="true" field="projectactivity">Project Activity</th>
                <th width="100" sortable="true" field="target">Target</th>
                <th width="100" sortable="true" field="actual">Actual</th>
                <th width="75" sortable="true" field="problemident">Problem Identification</th>
                <th width="75" sortable="true" field="correctiveact">Corrective Action</th>
                <th width="75" sortable="true" field="duedate">Due Date</th>
                <th width="75" sortable="true" field="PIC">PIC</th>
            </tr>
        </thead>
    </table>
...
...

这是文件get_project_detail.php

<?php 
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$sort = isset($_POST['sort']) ? strval($_POST['sort']) : 'projectactivity';
$order = isset($_POST['order']) ? strval($_POST['order']) : 'asc';
$projectname = isset($_POST['projectname']) ? mysql_real_escape_string($_POST['projectname']) : '';
$offset = ($page-1)*$rows;
$result = array();  
include 'conn.php';
$where = "projectactivity like '%$projectname%'";
$rs = mysql_query("select count(*) from dproject");
$row = mysql_fetch_row($rs);
$result["total"] = $row[0];
$rs = mysql_query("select * from dproject where " . $where . " order by $sort $order limit $offset,$rows");
$items = array();
while($row = mysql_fetch_object($rs)){
    array_push($items, $row);
}
$result["rows"] = $items;
echo json_encode($result);
?>

这是数据库表:
项目
idproject
分类
项目名称
目标
图片
电子邮件图片
开始
结束日期
进展

dproject
idd项目
idproject
项目活动
目标
实际
有问题
纠正措施
截止日期
图片

我们可以在文件projectdetail.php中看到2个表格
第一个表从数据库上的表 project 中获取数据,第二个表从数据库上的表 dproject 中获取数据。
第一个表是成功地根据从文件 project.php 发送的 id 获取数据。
但是在第二张表上,我想根据 projectdproject 之间的相同 ID 从表 dproject 中获取数据,可能就像这样 project .idproject=dproject.idproject 但它不起作用。大家能解释一下我的错误代码在哪里吗?

【问题讨论】:

    标签: php jquery mysql jquery-easyui


    【解决方案1】:

    我看到您想显示为子网格,对吗? Easyui有这个功能,你可以轻松使用,请看教程,看demo。

    http://www.jeasyui.com/tutorial/datagrid/datagrid22.php

    您可以以此作为理解结构文件的参考:

    1. 表的主文件,例如:project_list.php(输出为 html,body 表生成网格)
    2. 获取数据的文件 project_data_json.php(输出为 json 编码)
    3. 获取第二个数据库网格项目详细信息列表的文件,例如:project_detail_json.php(输出为 json 编码)

    查看示例代码 onExpandrow,你应该链接到 project_detail_json.php 不要忘记你应该在这里下载js文件http://www.jeasyui.com/easyui/datagrid-detailview.js

    【讨论】:

    • 如果这是正确答案,请标记为答案。谢谢。
    猜你喜欢
    • 2013-09-04
    • 1970-01-01
    • 1970-01-01
    • 2012-04-21
    • 2023-03-26
    • 2017-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多