Jump to content

ajax php mysql search problem


Vizonz

Recommended Posts

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 :P but it seems more a mysql problem then any of the others

Link to comment
https://forums.phpfreaks.com/topic/208689-ajax-php-mysql-search-problem/
Share on other sites

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.

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 ;(

$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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.