My databse is:
CREATE TABLE `user` (
`id` int(4) NOT NULL auto_increment,
`name` varchar(77) NOT NULL,
`pass` varchar(77) NOT NULL,
`datetime` varchar(22) NOT NULL,
`level` varchar(33) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;
INSERT INTO `user` VALUES (1, 'majid', '123', '2012-04-16', 'admin');
INSERT INTO `user` VALUES (2, 'feras', '123', '2012-04-15', 'gs');
INSERT INTO `user` VALUES (3, 'sami', '123', '2012-04-12', 'gs');
INSERT INTO `user` VALUES (4, 'rashed', '123', '2012-04-09', 'gs');
INSERT INTO `user` VALUES (5, 'saad', 'dfd', '2012-04-13', 'bb');
My search page is a form with three dropdown lists... first for name, second for pass and third for level.
Now, if I choose one drop list it will gives me a good result, but if I choose two or more lists it does not give me anything.
How can I make all that dropdown lists act like a filter for a specific result? Like "all pass (123) and level (gs)"
My query is:
$name= $_GET['name'];
$pass= $_GET['pass'];
$level= $_GET['level'];
mysql_select_db($database_sqltest, $sqltest);
$query_Recordset1 = "SELECT * FROM user WHERE '$name' OR pass LIKE '$pass' OR level LIKE '$level'";
$Recordset1 = mysql_query($query_Recordset1, $sqltest) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
You need to use AND
operator instead of OR
to increase specificity and limit the query. I've added %
signs (wildcards) so that a search for "12" would match pass "123". You can remove them if you won't want that functionality.
$query_Recordset1 = "SELECT * FROM user WHERE `pass` LIKE '%$pass%' AND `level` LIKE '%$level%' AND `name` LIKE '%$name%'";