I am using an html form with 6 criteria, using $_POSTlat convert criteria in variables, like here:
Case 1 - All default criteria -
$core = null; $mhz = null; $ram = null; $cam = null; $mAh = null $screen = null
Correct sql query:
$sql = "SELECT * FROM $tbl_name ORDER BY performanta_cpu_core DESC, performanta_cpu DESC, performanta_rami DESC LIMIT $start, $limit";
Case 2 - only one criterion is specified.
$core = null; $mhz = "performanta_cpu=1400"; $ram = null; $cam = null; $mAh = null $screen = null
Request corect:
$sql = "SELECT * FROM $tbl_name WHERE $mhzz ORDER BY performanta_cpu_core DESC, performanta_cpu DESC, performanta_rami DESC LIMIT $start, $limit";
Case 3 is the problem. All or more of the criteria:
$core = 2; $mhz = "performanta_cpu=1400"; $ram = "performanta_rami=1024"; $cam = "camera_spate=3.2"; $mAh = "baterie_mAh=2250"; $screen = "densitate=441";
I understand that I need to make " WHERE" dynamic and visible only when some variable is set, and I also need " AND" dynamically:
$sql = "SELECT * FROM $tbl_name WHERE $core AND $mhzz ORDER BY performanta_cpu_core DESC, performanta_cpu DESC, performanta_rami DESC LIMIT $start, $limit";
I have been tense for a week with this, and I cannot advance without help ...
Thanks in advance
NiTrO source
share