I am working in php and phonegap. i am sending title, category of song using url to php page. now i want to select songs according to title and category if these both are provided in url. if url providing only title then search must be done according to title only. and if url providing category only then search must be basis on the category only.
**this is code which i am trying**
$titletosearch = $_GET["title"];
$categorytosearch = $_GET["category"];
$artisttosearch = $_GET["artist"];
if($titletosearch !=" " && $titletosearch!=" ")
$rs = mysql_query("SELECT title,price,date,category FROM music where title like '%$titletosearch%' or category like '%$categorytosearch%' ") or die ("invalid query");
elseif($titletosearch =="" && $titletosearch!=" ")
$rs = mysql_query("SELECT title,price,date,category FROM music where category like '%$categorytosearch%' ") or die ("invalid query");
elseif($titletosearch !=" " && $titletosearch=="")
$rs = mysql_query("SELECT title,price,date,category FROM music where title like '%$titletosearch%' ") or die ("invalid query");
Problem with my code is this whenever i provide title only or category only in url then it searches so many records. means it work properly if i provide both title and category. if any of them is not given then i provide so many results records.
Please help how should i handle these conditions. ?
Thank you in advance.