Jump to content

If Statement Annoyance


dsartain

Recommended Posts

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??

Link to comment
https://forums.phpfreaks.com/topic/135032-if-statement-annoyance/
Share on other sites

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);
}
?>

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!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.