Chatlogs filteren

Gestart doorTmeiland8 reacties30 weergaven

9 berichten · pagina 1 van 1

Tmeiland

Lid · Topicstarter

Berichten
450
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hallo,

Ik heb een vraagje ik heb in mijn database een tabel staan genaamd chatlogs,
ik wil de chatlogs uitlezen en checken als er een black-listed woord in de tabel staat
iemand een idee hoe ik dit kan fixxen want t werkt niet

ik heb nu dit:

$string = "scheldwoord scheldwoord2";
$woorden = explode(, $string);

$filtertxt = mysql_fetch_array(mysql_query("SELECT * FROM chatlogs WHERE message=".$woorden." ORDER BY id"));
0
Berichten
6.485
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php
$words[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR]
    [COLOR= #DD0000]"klote"[/COLOR][COLOR= #007700],[/COLOR]
    [COLOR= #DD0000]"gangnam"[/COLOR]
[COLOR= #007700]);[/COLOR]



[COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"SELECT * FROM chatlogs WHERE "[/COLOR][COLOR= #007700];[/COLOR]

[URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$words[/COLOR] [COLOR= #007700]as[/COLOR] [COLOR= #0000BB]$word[/COLOR][COLOR= #007700]) {[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$word[/COLOR] [COLOR= #007700]==[/COLOR] [URL="http://www.php.net/end"]end[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$words[/COLOR][COLOR= #007700])) {[/COLOR]
        [COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700].=[/COLOR] [COLOR= #DD0000]"messages LIKE %."[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$word[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]"%"[/COLOR][COLOR= #007700];
    }[/COLOR]
    [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700].=[/COLOR] [COLOR= #DD0000]"messages LIKE %."[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$word[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]"% OR"[/COLOR][COLOR= #007700];
    }
}[/COLOR]

[COLOR= #0000BB]$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR] [COLOR= #FF8000]// ff snel [/COLOR]

[COLOR= #0000BB]$logs[/COLOR] [COLOR= #007700]=[/COLOR] null[COLOR= #007700];[/COLOR]

[URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_array"]mysql_fetch_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700]) {[/COLOR]
    [COLOR= #0000BB]$logs[/COLOR][COLOR= #007700][] =[/COLOR] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700];
}[/COLOR]

[COLOR= #FF8000]// $logs bevat alle messages met scheldwoorden[/COLOR]
?>
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Mooie titel ook weer. Hij is de hulp niet waard, meteen slotje als ik het kon beslissen.
0
Berichten
1.296
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Antonn schreef:
Mooie titel ook weer. Hij is de hulp niet waard, meteen slotje als ik het kon beslissen.
Wajooo jij bent echt meteen negatief tegen mensen enz ? doe eens normaal want dit doe je wel vaker -,-
0
Tmeiland

Lid · Topicstarter

Berichten
450
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Parse error: syntax error, unexpected {

Line:

while($row = mysql_fetch_array($query) {
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
) vergeten. Zie je meteen.
0
Tmeiland

Lid · Topicstarter

Berichten
450
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Idd, dom van meyummie
bedankt=D

Maar nu krijg ik dityummie
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near %.klote% ORmessages LIKE %.gangnam% at line 1
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
foreach($words as $word) {
    if($word == end($words)) {
        $sql .= "messages LIKE %.".$word."%";
    }
    else {
        $sql .= "messages LIKE %.".$word."% OR ";
    }
}


Moeilijk hé, errors lezen wink
Staat duidelijk in:
%.klote% ORmessages LIKE %.gangnam%

Wat klopt daar niet? OR en messages horen niet aan elkaar..

Achter die OR moet een spatie
$sql .= "messages LIKE %.".$word."% OR ";
0
Tmeiland

Lid · Topicstarter

Berichten
450
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik heb nu dit gemaakt,
en t werk perfect, maar als er in de database tabel message hallo gangnam staat dan gebeurt er niks. alleen gangnam dan werkt t wel:

$words = array(
"klote",
"gangnam"
);

foreach($words as $word) {
if($word == end($words)) {

$filtertxt = mysql_fetch_array(mysql_query("SELECT * FROM chatlogs WHERE message=".$word.""));

}
}
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren