I am trying to put a searchable database up that uses several terms to search for a song. These are $stype - type of search (Title only or Title and words), $skind - Kind of song - Hymn, Chorus etc $stempo - fast, slow etc. I need the database to be searched if they have a word to search on ($srch) or not. I am having problems with using nested if’s to account for all the different combinations. The problem is I’m not sure of the syntax with ifs. I would appreciate any help or if you have a different way it can be done. The offending code is below
$srch = $_POST['srch'];
$stype = $_POST['stype'];
$skind = $_POST['skind'];
$stempo = $_POST['stempo'];
if($srch == '') {$q ="SELECT * FROM songs ";
if ($skind !== 'All' AND $stempo =='All'){$q = $q."WHERE KIND = '$skind'";}
elseif ($skind == 'All' AND $stempo !=='All'){$q = $q."WHERE TEMPO = '$stempo'";}
elseif ($skind !== 'All' AND $stempo !=='All'){$q = $q."WHERE TEMPO = '$stempo' AND KIND = '$skind'";}
elseif ($stype == 'Title') {$q ="SELECT * FROM songs WHERE title LIKE '%$srch%'";} else {$q ="SELECT * FROM songs WHERE words LIKE '%$srch%' OR title LIKE '%$srch%'";}
if ($SKIND !== 'All' AND $stempo =='All'){$q = $q."and KIND = '$skind'";}
elseif ($SKIND == 'All' AND $stempo !=='All'){$q = $q."and TEMPO = '$stempo'";}
elseif ($SKIND !== 'All' AND $stempo !=='All'){$q = $q."and TEMPO = '$stempo' AND KIND = '$skind'";}
}
$q = $q." ORDER BY Title";
print $q;