开发者

Link 2 tables with Flexigrid

Hey Guys I have run in a bit of a problem here. I have 2 tables I want to link to get a name for a lookup id which is all straight forward but doing so with flexigrid is a pain because of the way you should build you're query. This is the code I currently use but you get the output of开发者_JS百科 a thousand records which should only be 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);

See when i put in WHERE tbl_p2e_place.CityID = tbl_lu_city.CityID in any of the most logical places it still does the same. Is there any other way I can accomplish this? Even if I have to use jqgrid or any equivalent tech?

Regards

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜