ohdang888 Posted June 14, 2008 Share Posted June 14, 2008 can this be done? i have 6 search fields, and there might be 1 filled, or all 6 might be filled. So i want to search by how many fields they've entered. Can this be done in one query? example: <?php $result = mysql_query("SELECT * FROM `common_traits WHERE if(isset($genus)){genus='$genus'} AND if(isset($var2)){genus='$var2} ") or die(mysql_error()); ?> thanks! Link to comment https://forums.phpfreaks.com/topic/110225-php-inside-of-a-mysql-query/ Share on other sites More sharing options...
tapos Posted June 14, 2008 Share Posted June 14, 2008 no not this way u can use it. what about this $where = ''; if(isset($var1)) { $where? $where .= " AND var1 = '$var1' " : $where = " var1 = '$var1' " } if(isset($var2)) { $where? $where .= " AND var2 = '$var2' " : $where = " var2 = '$var2' " } if(isset($var3)) { $where? $where .= " AND var3 = '$var3' " : $where = " var3 = '$var3' " } . .//so on . $result = mysql_query("SELECT * FROM `common_traits WHERE $where ") or die(mysql_error()); hope this will help u Link to comment https://forums.phpfreaks.com/topic/110225-php-inside-of-a-mysql-query/#findComment-565591 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.