1
我試圖創建一個簡單的搜索頁面,但我不是100%確定如何編寫實際的搜索字符串(使用適當和的等如果變量存在)下面的代碼:動態創建一個mysql搜索字符串?
if ($post) {
//get all search variables
$type = JRequest::getVar('type');
$classifications = JRequest::getVar('classifications', array(0), 'post', 'array');
$rating = JRequest::getVar('rating');
$status = JRequest::getVar('status');
$cterms = JRequest::getVar('cterms');
$clientid = JRequest::getVar('clientid');
$company = JRequest::getVar('company');
$address = JRequest::getVar('address');
$name = JRequest::getVar('name');
$surname = JRequest::getVar('surname');
$city = JRequest::getVar('city');
$state = JRequest::getVar('state');
$pcode = JRequest::getVar('pcode');
$country = JRequest::getVar('country');
//create search string
echo "SELECT * FROM #__db_clients "; <- the query is supposed to be done here.. it's in as echo because I was trying to spit it out before trying to make it run.. :)
} else {
echo 'There has been an error, please try again.';
};
我已經嘗試使用(如果type!= null,則檢索類別=「其中type =‘X’」),但我無法弄清楚如何放置和/後,如果之前它需要的搜索..如果讓感?
將內容插入到表達式中時,一定要將轉義應用於'$ v'。 – 2009-09-15 01:36:53
@ Bill Karwin - 絕對謝謝!我不知道哪個轉義方法適用於他的應用程序,所以我在答案中寫了一個註釋(以及代碼註釋)。 – karim79 2009-09-15 01:40:32
非常感謝,這肯定會幫助我得到我的代碼:)非常感謝! – SoulieBaby 2009-09-15 01:42:31