hi,
i'm trying use a for loop to stop certain records being shown from a query
if my array contains something then i want it to output the necessary sql code to stop it from retrieving those results
eg.
$array = array('XBOX');
then my sql query should be
SELECT DISTINCT platformFROM
cheatsWHERE
platform` != 'XBOX'
i ran this through phpmyadmin and it worked fine
however when i try to use this script to do the same thing it doesnt work.
<?
function exclude($whereex) {
$exc_list = array('XBOX');
if (count($exc_list) != 0) {
if ($whereex) {
return "AND \n";
}
else {
return "WHERE \n";
}
for ($i=0;$i<count($exc_list);$i++) {
return "`platform` != ".$exc_list[$i]."'\n";
if (($i-1) < count($exc_list)) {
return " AND ";
}
}
}
}
$sql = "SELECT DISTINCT `platform` FROM `cheats` ".exclude(FALSE);
?>
when i check my source i get this error
SELECT DISTINCT platform
FROM cheats
WHERE
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 '' at line 1
but i'm not quite sure where i'm going wrong.
any help appreciated
Jon