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

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

 

 

Perfect, that worked!  Thanks!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.