Query Filter

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ra
Forum Commoner
Posts: 58
Joined: Fri Mar 25, 2005 4:25 pm

Query Filter

Post by ra »

I am trying to get the following script to filter out a lengthy list of unfavorable words (in a text file?), but i am extremely lost. Any help would be greatly appreciated.

Code: Select all

<?
function format_term($term) {
$term = str_replace('-','~~',$term);
return str_replace(' ','-',$term);
}
$res = mysql_query("SELECT * FROM $querytable ORDER BY q_id DESC") or die(mysql_error());
 
if (preg_match($pattern, $searchstring)) {
do_insert();
}
while (($line = mysql_fetch_assoc($res)) && strlen(ob_get_contents()) < 95*1024) {
echo "<a href='".constant('dir')."search/".format_term($line['q_query'])."'>".$line['q_query']."</a><br>";
}
?>
</div>
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

it's hard to understand what your posted code is doing...

but if you are retrieving the unfavorable words from a database, you could easily build your own array with words (and replacements) and then perform a strreplace or a preg_replace

in general, code would look like:

Code: Select all

$unfavorables = array();
$replacements = array();

$query = "SELECT unfavorable from table";
$result = mysql_query($query) or die(mysql_error());

while ($rows = mysql_fetch_assoc($result))
{
  $unfavorables[] = $row['word'];
  $replacements[] = '';
}

$filecontent = str_replace($unfavorables, $replacements, $filecontent);
ra
Forum Commoner
Posts: 58
Joined: Fri Mar 25, 2005 4:25 pm

Post by ra »

I was hoping to put the bad words in a text file on the server that i could update frequently. And there is no need to replace the terms, just show actual terms that are filtered... What do you think? And thanks for responding.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Now, here, we know the source of keywords/badwords and we know the procedure for replacing/highlighting but where do we have to search them. you don't mention that anywhere... :?
ra
Forum Commoner
Posts: 58
Joined: Fri Mar 25, 2005 4:25 pm

Post by ra »

I was hoping to store the words in a text file on the server... is that what you mean?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

I mean where do you want them replaced :?:
ra
Forum Commoner
Posts: 58
Joined: Fri Mar 25, 2005 4:25 pm

Post by ra »

I don't want them replaced; just removed from the original query. The page this code resides on pulls all of the search terms out of the db and displays everything. I want to be able to create a text file on the server that has a list of terms to remove from the display... Does that make sense?
Sphen001
Forum Contributor
Posts: 107
Joined: Thu Mar 10, 2005 12:24 pm
Location: Land of the Beaver

Post by Sphen001 »

If I understand you correctly, you should probably use a loop to remove all of the bad words from the DB first, and then you can just get the full contents of the DB, and don't worry about the bad words. I don't know if it's possible to do it on the fly like you want...

Sphen001
ra
Forum Commoner
Posts: 58
Joined: Fri Mar 25, 2005 4:25 pm

Post by ra »

I think the probablem with removing the terms from the DB is that they are constantly being put back in by users and other search engines. Can I use the loop method in an environment like this and, if yes, how?
ra
Forum Commoner
Posts: 58
Joined: Fri Mar 25, 2005 4:25 pm

Post by ra »

is there a way to filter the database and then post those results as static content, and then refresh that content every hour?
ra
Forum Commoner
Posts: 58
Joined: Fri Mar 25, 2005 4:25 pm

Post by ra »

help?
ra
Forum Commoner
Posts: 58
Joined: Fri Mar 25, 2005 4:25 pm

Post by ra »

here is the page:

http://www.sodora.com/queries.html

I am manually adjusting values in the db for the bad words...
Post Reply