Dynadot โ€” .com Registration $8.99

Need help with a php while loops

Spaceship Spaceship
Watch

Jawn

Straight from SwedenEstablished Member
Impact
2
What it does is that it gets sites from a database, however some sites contain illegal strings like rapidshare.com and i dont want those sites to be listed.
So i have created another while in the other while loop which loops through a database with illegal strings but it doesnt seem to work.
It only works when theres one illegal string in the database :/ if i have more it doesnt work.

Would greatly appreciate if someone had a look


Best Regards


Code:
            //Get sites
	while($article = mysql_fetch_assoc($result)){

		$siteID			= $article['feed_id'];
		$article_ID		= $article['article_id'];
		$articleTitle 		= $article['title'];
		$article_Description	= $article['summary'];


		// Here we get all forbidden strings
		$data = mysql_db_query($databaseName, "SELECT strings FROM `evots_filter` WHERE 1");

		// loops through all the strings and check
		while($row = mysql_fetch_array($data)) {

			$filterWord = $row['strings'];

  			$pos = strpos($article_Description, $filterWord);
			if ($pos === false) {


					print('<li>');
					print('<div class="article">');
					printf('<h2><a href="/out.php?site=%s&article=%s" target="_blank" rel="external">%s</a></h2>',$siteID, $article_ID, $articleTitle);
					printf('<div class="article_date">%s</div>', $article["date_posted"]);
					printf('<div class="article_summary">%s</div>', $article_Description);
					print('</div>');
					print('</li>');

			}
			else{
				

			}

		}
	}
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
I would suggest you add all the "bad" words to a variable first, then use a SEPERATE while loop to take out those URLs.

I'm not quite sure how your db and stuff is set up, and I can't seem to use your code to show you, but you want something like this:
PHP:
$sql = "GET ALL BAD WORDS FROM DATABASE";
$count = 0;

while($row = mysql_fetch_array(mysql_query($sql))){

  $filterwords[$count] = $row['string'];

  $count++;

}

// now you have the variable $filterwords with all the bad words stored in it.

// now you have to get all the urls and check each one...
$sql = "GET ALL THE URLS FROM THE DATABASE";

while($row = mysql_fetch_array(mysql_query($sql))){

   // some fancy code here searching the string for any of the filterwords, something like:
  $count = 0;
  while(!empty($filterwords[$count])){
    $pos = strpos($article_Description, $filterwords[$count]);
    if ($pos === false && !$bad) {
      $bad = false;
    }
    else{
      $bad = true;
    }
    $count++;
  }

}

very rushed code, and am a bit rusty - but you get the jist ;)

Saves you searching the database for filterwords for EVERY url. :D
 
0
•••
Unstoppable Domains
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back