dsartain Posted December 1, 2008 Share Posted December 1, 2008 Hey guys, I'm having some trouble with this if statement. I'm writing a text file (yes, has to be a text file) and some items have three keywords, some have between 4 and 7. I've written this if statement to filter out where keywords 4-7 are blank, but so far it's not working. Both below if statements still print the keywords 4-7 even when there isn't a word there. if(stripslashes($row['keyword4'])!=NULL or stripslashes($row['keyword4']) !=" ") { $stringData2 = "".stripslashes($row['network'])."2, ".stripslashes($row['advertiser']).", ".stripslashes($row['keyword4']).", ".stripslashes($AdURL).", 0.20, Active\n"; fwrite($fh2, $stringData2); } if(stripslashes($row['keyword4'])!="" or stripslashes($row['keyword4']) !=" ") { $stringData2 = "".stripslashes($row['network'])."2, ".stripslashes($row['advertiser']).", ".stripslashes($row['keyword4']).", ".stripslashes($AdURL).", 0.20, Active\n"; fwrite($fh2, $stringData2); } I have also tried the above with single quotes instead of double. When I run SELECT * FROM ad_links3.link_table l WHERE keyword4=" "; on the DB, I get results. So this if statement should eliminate those if the mysql is responding to " " for keyword4, but it's not... This is what this code produces when run through a loop, lines 4-7 should not be there as there is no keyword... CB2, Google.com, Google.com, http://www.adclicktracking.com/CB/Google.html?keyword={keyword}G, 0.20, Active CB2, Google.com, Google com, http://www.adclicktracking.com/CB/Google.html?keyword={keyword}G, 0.20, Active CB2, Google.com, Googlecom, http://www.adclicktracking.com/CB/Google.html?keyword={keyword}G, 0.20, Active CB2, Google.com, , http://www.adclicktracking.com/CB/Google.html?keyword={keyword}G, 0.20, Active CB2, Google.com, , http://www.adclicktracking.com/CB/Google.html?keyword={keyword}G, 0.20, Active CB2, Google.com, , http://www.adclicktracking.com/CB/Google.html?keyword={keyword}G, 0.20, Active CB2, Google.com, , http://www.adclicktracking.com/CB/Google.html?keyword={keyword}G, 0.20, Active Any ideas?? Quote Link to comment Share on other sites More sharing options...
flyhoney Posted December 1, 2008 Share Posted December 1, 2008 I believe you are using 'or' when you want to use 'and'. Quote Link to comment Share on other sites More sharing options...
dsartain Posted December 1, 2008 Author Share Posted December 1, 2008 No, it's testing the same field for either values "" (NULL) or " " (space)...so or should be the right word... Quote Link to comment Share on other sites More sharing options...
flyhoney Posted December 1, 2008 Share Posted December 1, 2008 Why don't you change it to something like this: <?php if (trim($row['keyword4'])) { $stringData2 = "".stripslashes($row['network'])."2, ".stripslashes($row['advertiser']).", ".stripslashes($row['keyword4']).", ".stripslashes($AdURL).", 0.20, Active\n"; fwrite($fh2, $stringData2); } ?> Quote Link to comment Share on other sites More sharing options...
dsartain Posted December 1, 2008 Author Share Posted December 1, 2008 Why don't you change it to something like this: <?php if (trim($row['keyword4'])) { $stringData2 = "".stripslashes($row['network'])."2, ".stripslashes($row['advertiser']).", ".stripslashes($row['keyword4']).", ".stripslashes($AdURL).", 0.20, Active\n"; fwrite($fh2, $stringData2); } ?> Perfect, that worked! Thanks!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.