TD Posted February 25, 2008 Share Posted February 25, 2008 Hi, I have a little problem, but can't figure it out, how can i fix it?!?!? I would very appreciate any help. DB: Name: Johny Texas Knight Surname: Walker Ranger Rider I have only one search box and when i search one string like Johny or Walker everything works fine, but when i write them together, they just don't show up. My php code looks so: if (empty($name)) { $nam = ""; $nam2 = ""; } else { $nam = "where (vards='$name' or uzvards='$name')"; $nam2 = "and vards='$name' or uzvards='$name')"; } How should I write it correctly so that the script understands? Many thanks, hope You understand, what am i asking. Link to comment https://forums.phpfreaks.com/topic/92882-search-multiple-fields-without-having-exact-matches/ Share on other sites More sharing options...
fenway Posted February 25, 2008 Share Posted February 25, 2008 You're missing an open paren in nam2. Link to comment https://forums.phpfreaks.com/topic/92882-search-multiple-fields-without-having-exact-matches/#findComment-475812 Share on other sites More sharing options...
TD Posted February 25, 2008 Author Share Posted February 25, 2008 I will post the whole script: if (empty($name)) { $nam = ""; $nam2 = ""; } else { $nam = "where (name='$name' or surname='$name')"; $nam2 = "and name='$name' or surname='$name')"; } if (empty($region)) { $regi = "$nam"; } else { $regi = "where (regions='$region' $nam2)"; } $sql = mysql_query("SELECT * FROM $tab $regi order by name, surname asc"); Link to comment https://forums.phpfreaks.com/topic/92882-search-multiple-fields-without-having-exact-matches/#findComment-475817 Share on other sites More sharing options...
fenway Posted February 25, 2008 Share Posted February 25, 2008 Echo the $sql variable for each flow path. It's much easier to collect each condtiion, then build the where clause at the end (i.e. by join-ing an array with ANDs). You still have unpaired parens. Link to comment https://forums.phpfreaks.com/topic/92882-search-multiple-fields-without-having-exact-matches/#findComment-475854 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.