php mysql query
I try to print this:
$idg = array_filter(explode(",", $IDGruppo)); //url string
$idv = array_filter(explode(",", $IDVarianti)); // url string
$sql = "SELECT * FROM ccc WHERE ";
foreach($idg as $v)
{
foreach($idv as $c)
{
$sql .= "IDG = '". $v ."' AND IDF = '".$c."' AND Cancellato = '0' ";
if ( count($idv) != $i )
$sql .= "OR ";
$i++;
}
if ( count($idg) != $j )
$sql .= "OR ";
$j++;
}
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
'IDGruppo = '34' AND IDFamiglia = '130' AND Cance开发者_如何学Cllato = '0' OR IDGruppo = '34' A'
at line 1
Query:
SELECT * FROM catalogo_prodotti WHERE IDGruppo = '29' AND IDFamiglia = '130' AND Cancellato = '0' OR IDGruppo = '29' AND IDFamiglia = '142' AND Cancellato = '0' IDGruppo = '34' AND IDFamiglia = '130' AND Cancellato = '0' OR IDGruppo = '34' AND IDFamiglia = '142' AND Cancellato = '0' OR
You have extra OR
at the end.
In query your condition is getting missed in between. Check this section in query -
...AND Cancellato = '0' IDGruppo = '34' AND...
Also an extra OR at the end of query
Your query - SELECT * FROM ccc WHERE
You missed the conditional part id
=23 for instance
精彩评论