Vizonz Posted July 23, 2010 Share Posted July 23, 2010 found a little ajax script to display search results so i changed it up a little but when searching getting an error. anyone give me a hand finding out why.. $qry = "SELECT DISTINCT artist,label,genre,composer FROM songlist GROUP BY artist ORDER BY songlist.date_added"; $searchText = ""; if($_REQUEST['search_text']!=""){ $searchText = $_REQUEST['search_text']; $qry .=" where artist like '$searchText%'"; You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where artist like 'Artist%'' at line 2 if you need more info i will post more but maybe its just a error in that above code didnt know where to post this in ajax mysql or php but it seems more a mysql problem then any of the others Quote Link to comment https://forums.phpfreaks.com/topic/208689-ajax-php-mysql-search-problem/ Share on other sites More sharing options...
radar Posted July 23, 2010 Share Posted July 23, 2010 Have you tried echoing out your $qry and running that through phpmyadmin to see what it says? Whenever I have an SQL issue, thats the first thing I do, as even if i cant figure it out it gives me some further diagnostic information to post here along with the query itself. Quote Link to comment https://forums.phpfreaks.com/topic/208689-ajax-php-mysql-search-problem/#findComment-1090252 Share on other sites More sharing options...
Vizonz Posted July 23, 2010 Author Share Posted July 23, 2010 the query works its displaying all the results. but when i use the search box to find a specific thing thats where i get the error Quote Link to comment https://forums.phpfreaks.com/topic/208689-ajax-php-mysql-search-problem/#findComment-1090255 Share on other sites More sharing options...
radar Posted July 23, 2010 Share Posted July 23, 2010 My query is a bit different than yours, but it works for my search. note that i use the smarty template engine, and smarty paginate... but perhaps this will help you on your way too. $sql = "SELECT SQL_CALC_FOUND_ROWS * FROM employs WHERE l_name LIKE '".$_pid."%' LIMIT ". SmartyPaginate::getCurrentIndex().",".SmartyPaginate::getLimit(); perhaps its something so simple as making WHERE and LIKE capitals... or as a test you could get rid of the % and see if that works... if it doesnt work then try it like '".$searchText."%' and if that doesn't work i have no clue ;( Quote Link to comment https://forums.phpfreaks.com/topic/208689-ajax-php-mysql-search-problem/#findComment-1090268 Share on other sites More sharing options...
Vizonz Posted July 23, 2010 Author Share Posted July 23, 2010 thanks for trying tried all of the above and no result Quote Link to comment https://forums.phpfreaks.com/topic/208689-ajax-php-mysql-search-problem/#findComment-1090272 Share on other sites More sharing options...
Vizonz Posted July 23, 2010 Author Share Posted July 23, 2010 Anyone this is kinda important its set up and running besides the search. The results are in ajax pagination so thats working just the search dont function Quote Link to comment https://forums.phpfreaks.com/topic/208689-ajax-php-mysql-search-problem/#findComment-1090296 Share on other sites More sharing options...
PFMaBiSmAd Posted July 23, 2010 Share Posted July 23, 2010 You are building the query incorrectly. The specific parts of the query must be in a certain order - http://www.phpfreaks.com/forums/index.php/topic,305028.msg1442575.html#msg1442575 Quote Link to comment https://forums.phpfreaks.com/topic/208689-ajax-php-mysql-search-problem/#findComment-1090301 Share on other sites More sharing options...
dezkit Posted July 23, 2010 Share Posted July 23, 2010 $qry = "SELECT DISTINCT artist,label,genre,composer FROM songlist "; $searchText = ""; if($_REQUEST['search_text']!=""){ $searchText = $_REQUEST['search_text']; $qry .=" WHERE artist LIKE '$searchText%'"; } $qry .=" GROUP BY artist ORDER BY songlist.date_added"; try this Quote Link to comment https://forums.phpfreaks.com/topic/208689-ajax-php-mysql-search-problem/#findComment-1090304 Share on other sites More sharing options...
Vizonz Posted July 23, 2010 Author Share Posted July 23, 2010 thanks so much both of you that led to it working Quote Link to comment https://forums.phpfreaks.com/topic/208689-ajax-php-mysql-search-problem/#findComment-1090306 Share on other sites More sharing options...
radar Posted July 23, 2010 Share Posted July 23, 2010 I should have realized that fix the first go around... the where clause has to go directly after the table your selecting as it is now.. bah! Quote Link to comment https://forums.phpfreaks.com/topic/208689-ajax-php-mysql-search-problem/#findComment-1090315 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.