使用Flexigrid链接2个表

时间:2011-06-18 08:48:11

标签: php jquery ajax flexigrid

嘿伙计们我在这里遇到了一些问题。我有两个表,我想链接到一个查找ID的名称,这是直截了当的,但使用flexigrid这样做是一个痛苦,因为你应该建立你的查询方式。这是我目前使用的代码,但是你得到的千条记录的输出应该只有3个。

    //Setup sort and search SQL using posted data.
$sortSql = "ORDER BY $sortname $sortorder";
//$searchSql = ($qtype != '' && $query != '') ? "WHERE $qtype = '$query'" : 'WHERE tbl_p2e_place.CityID = tbl_lu_city.CityID';
$searchSql = ($qtype != '' && $query != '') ? "WHERE $qtype = '$query'" : '';

//Get total count of records
$sql = "SELECT COUNT(*) FROM tbl_p2e_place $searchSql";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$total = $row[0];

//Setup paging SQL
$pageStart = ($page -1)* $rp;
$limitSql = "LIMIT $pageStart, $rp";


//return JSON data
$data = array();
$data['page'] = $page;
$data['total'] = $total;
$data['rows'] = array();
$sql = "SELECT listingID, listingContractNumber, listingName, CityName 
        FROM tbl_p2e_place, tbl_lu_city
        $searchSql
        $sortSql
        $limitSql";
$results = mysql_query($sql);
while($row = mysql_fetch_assoc($results))
{
    $data['rows'][] = array(
    'id' => $row['listingID'],
    'cell' => array($row['listingID'], $row['listingContractNumber'],$row['listingName'], $row['CityName'])
    );
}

echo json_encode($data);

当我将WHERE tbl_p2e_place.CityID = tbl_lu_city.CityID放入任何最合乎逻辑的地方时,它仍然会保持不变。有没有其他方法可以实现这一目标?即使我必须使用jqgrid或任何等效的技术?

问候

0 个答案:

没有答案