display mysql query result from array parameters php -
i'll best explain create query return rows search function ex : return row id = __
here's code :
if(!empty($champs)){ $table[0]["prog"] = array('mydb.message','message'); $table[1]["prog"] = array('mydb.newtable','username','nom','prenom');
as table , columns
$nb_result =0; for($i =0 ; $i < count ($table); $i++) { $prog_tab = $table[$i]["prog"]; $sql = sprintf("select * %s 1 ", $prog_tab [0], default_access_level); for($j = 1; $j < count ($prog_tab ); $j++) { $sql .= sprintf(" or %s '%s' ", $prog_tab [$j], $this->ins_string("%".$champs."%"), default_access_level); } echo $sql; /*$sql = $table[$i]["user"][0] . ' ---> ' . $sql."<br>"; */ $query = mysql_query($sql) or die(mysql_error()); while($rows = mysql_fetch_array($query)){ if($table[$i]["prog"][1] == "message"){ echo $rows['sender']." :  ".$rows['message']."<br />"; } else{ echo $rows['username']." ".$rows['nom']." ".$rows['prenom']."<br />"; } } $nb_result += mysql_num_rows($query); } echo "<br /><h1>".$nb_result."</h1>"; }
the problem when display query returns rows 2 tables , ignore %$champs%
note* when display query seems fine : select * mydb.newtable 1 or username '%$champs%' or nom '%$champs%' or prenom '%$champs%'
, $nb_result returns 48 (amount of rows have in 2 tables combined )
a where
clause boils down boolean decision database, "include row, or don't include it". since you're doing
select ... 1 or ... or ... or ... ^--
you're producing 'true' value, rows match , included.
remember boolean truth tables. true or anything
true.
Comments
Post a Comment