Current location: Hot Scripts Forums » Programming Languages » PHP » A Language filter problem, and a problem with a for loop querying my database. . .


A Language filter problem, and a problem with a for loop querying my database. . .

Reply
  #1 (permalink)  
Old 05-07-05, 11:49 AM
Spreegem Spreegem is offline
Newbie Coder
 
Join Date: Jan 2004
Location: In front of my computer
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
A Language filter problem, and a problem with a for loop querying my database. . .

Ok, I read a tutorial http://www.phpfreaks.com/tutorials/122/1.php on how to create a language filter, however I was wondering if it wold be possible to use a MySQL database rather than a text file or an array. The reason I am askign is because I want my users to be able to make their own lists of words that they want to be blocked. Is it possible to do that? If so how would I have to change the code to do that, and how would the data in the database have to look? Would it have to be like word, word or something else to seperate the words?

I am also having a problem with a for loop querying my database and updating data. The loop is inserting all of the stuff in the array, rather than the ones that were selected. Anyone know what may be causing this?

PHP Code:

for($weap 1$weap 9$weap++)

        {
        
$we_num 'we_'.$weap;
        
$weapon $_POST['weapon']["$we_num"];
        
            if(
$weapon == $weap)
                {                    
                for(
$rows 1$rows 26$rows++)
                    {
                    
$tech 'weap_tech'.$rows;
                    
$type 'weap_type'.$rows;
                    
$dmg 'weap_dmg'.$rows;
                        
                    
$tech2 'we_tech'.$weapon;
                    
$type2 'we_type'.$weapon;
                    
$dmg2 'we_dmg'.$weapon;
                        
                    
$tech3 $_SESSION["$tech2"];
                    
$type3 $_SESSION["$type2"];
                    
$dmg3 $_SESSION["$dmg2"];

                    if(
$row2["$tech"] == 0)
                       {
                        
mysql_query("UPDATE ships SET $tech='$tech3', $type='$type3', $dmg='$dmg3' WHERE ship_name='$ship' AND owner='$user'") or die (mysql_error());
                        }
                    }
                }
        } 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 05-07-05, 01:50 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
well for the filter try:

PHP Code:

//Loop to get badword and newword from table

$query mysql_query("SELECT badword, newword FROM table_filter");
while(
$r mysql_fetch_array($query)) {
$badword $r['badword'];
$newword $r['newword'];

//Now replace words assuming the text is set in variable $message
str_replace($badword$newword$message);

__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 05-07-05, 02:12 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
FiRe's code will be case-sensitive and it wont give expected results because it didn't assign the changes to any variable
so to make your filter case-insensitive use eregi_replace()
PHP Code:

//Loop to get badword and newword from table

$query mysql_query("SELECT badword, newword FROM table_filter");

while(
$r mysql_fetch_array($query)) {
   
$badword $r['badword'];
   
$newword $r['newword'];

//Now replace words assuming the text is set in variable $message
   
$message eregi_replace($badword$newword$message);

__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 05-07-05, 05:02 PM
Spreegem Spreegem is offline
Newbie Coder
 
Join Date: Jan 2004
Location: In front of my computer
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Umm. . . How do the words in the database need to be in there? I want there to be multiple words in a row. Then the row with a few words gets selected, and I want it to check for each of the words that are in the row. And how do I need to have all of the words in the row? How do I seperate the words in the row so that it will check for each word in the row? That's what I need to know.

Also, is there anything wrong looking in for loop? everything looks fine to me, but it's just not working as intended.

Thanks for the help guys!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 05-08-05, 04:35 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
it is better to have a table for this.
a structure like this is good:
Code:
CREATE TABLE `filter` (
`id` MEDIUMINT( 4 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
`badWord` TINYTEXT NOT NULL ,
`replacement` TINYTEXT NOT NULL ,
PRIMARY KEY ( `id` ) 
);
put each unwanted word in the row "badWord" and its replacement in "replacement"
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 05-08-05, 04:56 AM
DA Master DA Master is offline
Wannabe Coder
 
Join Date: Jun 2003
Location: Yorkshire
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
You could have a full line seperated by comas, this would get messey though.

I would have seperate rows.
__________________
PHP Code:

<?php if(PHP_OS == 'Windows') { echo "Doh"; } ?>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 05-08-05, 12:03 PM
Spreegem Spreegem is offline
Newbie Coder
 
Join Date: Jan 2004
Location: In front of my computer
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Ok cool, guess I'll just do that then with seperate rows
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 10:48 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.