// grab the search types.
$searchSQL = "SELECT * FROM jsprofile WHERE ";
$types = array();
$types[] = isset($_GET['sicno'])?"`name` LIKE '%{$searchTermDB}%'":'';
$types[] = isset($_GET['sname'])?"`icno` LIKE '%{$searchTermDB1}%'":'';
$types[] = isset($_GET['sgender'])?"`gender` LIKE '%{$searchTermDB2}%'":'';
$types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked)
if (count($types) < 1)
$types[] = "`icno` LIKE '%{$searchTermDB}%'"; // use the body as a default search if none are checked
$andOr = isset($_GET['matchall'])?'AND':'AND';
$searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `icno`"; // order by title.
$searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}");
// if (mysql_num_rows($searchResult) < 1) {
/// $error[] = "The search term provided {$searchTerms} yielded no results.";
從此一切正常。我能搜索......然而,當我試圖連接兩個表..SQL自定義搜索功能:無法加入兩個表格
// grab the search types.
$searchSQL = "SELECT * FROM jsprofile INNER JOIN medi WHERE ";
$types = array();
$types[] = isset($_GET['sicno'])?"`name` LIKE '%{$searchTermDB}%'":'';
$types[] = isset($_GET['sname'])?"`icno` LIKE '%{$searchTermDB1}%'":'';
$types[] = isset($_GET['sgender'])?"`gender` LIKE '%{$searchTermDB2}%'":'';
$types[] = isset($_GET['medical'])?"`medical` LIKE '%{$searchTermDB2}%'":'';
$types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked)
if (count($types) < 1)
$types[] = "`icno` LIKE '%{$searchTermDB}%'"; // use the body as a default search if none are checked
$andOr = isset($_GET['matchall'])?'AND':'AND';
$searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `icno`"; // order by title.
$searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}");
// if (mysql_num_rows($searchResult) < 1) {
/// $error[] = "The search term provided {$searchTerms} yielded no results.";
當我做這個..似乎沒有出來有什麼不對的查詢?
嗯..它沒有真正的工作,它仍然顯示一個空白屏幕 – Kelvin 2011-06-07 06:12:59