1

嘿伙计们,我在这里遇到了一些问题。我有 2 个表,我想链接以获得查找 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 或任何等效技术?

问候

4

0 回答 0