I would like to create a sql request if my array contains elements :
$sql = '';
$sql.= 'SELECT * FROM maisons, chambres.numero, chambres.etage, chambres.prix, chambres.charges, chambres.id';
$sql.= ' LEFT JOIN chambres';
$sql.= ' ON maisons.id = chambres.maison_id';
$sql.= ' WHERE ';
if(isset($tab))
{
//$str_cp = implode(', ', $tab);
//$sql.= 'maisons.commune_id IN '.$str_cp;
if(count($tab) > 0)
{
for($i=0; $i<count($tab);$i++)
{
$sql.= 'commune_id = '.$tab[$i].' OR ';
}
}
}
I'm obtaining this query :
SELECT * FROM maisons, chambres.numero, chambres.etage, chambres.prix, chambres.charges, chambres.id LEFT JOIN chambres ON maisons.id = chambres.maison_id WHERE commune_id = 8 OR
If I copy paste this query into phpmyadmin, I obtain this error :
#1142 - SELECT command denied to user 'bestinvewabi'@'10.0.120.18' for table 'numero'
By the way, do you have a better way to construct the WHERE of my query ?
WHERE 1=1that I dont need and if statement I can just loop through and addAND Field = ?