首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Jquery EasyUI中的两个mysql表中选择数据

从Jquery EasyUI中的两个mysql表中选择数据
EN

Stack Overflow用户
提问于 2014-05-07 04:19:31
回答 1查看 2.5K关注 0票数 0

嗨,我是使用的新成员。我创建了3个文件,project.php、projectdetail.php和get_project_detail.php

这是我的project.php代码

代码语言:javascript
复制
...
...
<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>

我使用格式化程序="formatProjectId"将id值抛出为projectdetail.php文件

这是文件projectdetail.php

代码语言:javascript
复制
...
...
<?
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

代码语言:javascript
复制
<?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

iddproject

idproject

项目活动

目标

实际

有问题

纠正行为

杜伊达

图图

我们可以在文件projectdetail.php中看到两个表

第一个表从数据库上的表项目获取数据,第二个表从数据库上的表dproject获取数据。

第一个表是成功地根据从文件project.php.发送的id获取数据。

但是,在第二个表中,我想从表project.idproject=dproject.idproject中获取数据,它基于项目dproject之间的相同id,可能与这个类似,但它不起作用。大家能给我解释一下我的错误代码在哪里吗?

EN

回答 1

Stack Overflow用户

发布于 2014-08-29 21:38:07

我看到你想要显示为子网格,对吗?Easyui有这个特性,您可以轻松使用,请看教程,并查看演示。

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

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

  1. 表的主文件,ex: project_list.php (输出为html,主体表生成网格)
  2. 用于get数据project_data_json.php的文件(输出为json编码)
  3. 获取第二个db网格的文件项目详细列表,ex: project_detail_json.php (输出为json编码)

查看示例代码onExpandrow,您应该链接到project_detail_json.php --不要忘记在这里下载js文件

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23508658

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档