Hallo allemaal,

Ik ben bezig om onze starwars jk3 (quake based) bot om te zetten in php , zodat iedereen er gebruik van kan maken.

het moet dus zo worden dat als iemand een zin in het input box typt , hij de overeen komende vragen en antwoorden opzoekt , daaruit weer preciezer zoekt en dan een van de meest overeenkomende antwoorden terug naar de game server stuurd via rcon.

Voorbeeld:

iemand zegt: where the hell is the shop , dan zoekt hij voor: where , the , hell , is , the ,shop

en moet hij alle resultaten echoén om te laten zien of de eerste stap goed werkt.

Het werkt alleen nog niet helemaal dit is wat ik tot nu toe heb in de database:

id |question | answer
1 |where shop |The shop is near the bar.
2 |what the hell | This is heaven!
3 |Where is bar |The bar is near the shop.
4 |Is difficult bot |No it is not difficult to be a bot.
5 |go home |No I don't want to go home!

Dit is mijn script:

<?php require ('includes/connect.php') ;?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Bot</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
If (!isset($_POST['submit'])){
?>
<table style="width: 100%;">
<tr>
<form action="index.php" method="post"></td>
<td></td>
</tr>
<tr>
<td style="width: 40%;">Input</td>
<td style="width: 60%;"><input type="text" name="input" size="30" />
</tr>
<tr>
<td style="width: 40%;"></td>
<td style="width: 60%;"><input style="width:30%;" type="submit" name="submit" value="Submit" /></form></td>
</tr>
</table>

<?php
}Else{
$inputnot = trim($_POST['input']);
$inputnot = str_replace('.',' ',$inputnot);
$inputnot = str_replace('?',' ',$inputnot);
$inputnot = str_replace(',',' ',$inputnot);
$inputnot = str_replace(':',' ',$inputnot);
$inputnot = str_replace(';',' ',$inputnot);
$inputnot = str_replace(' ',' ',$inputnot);//moet 2 keer om de "bla , bla" dingen op te lossen
$inputnot = str_replace(' ',' ',$inputnot);
$inputarray = explode(" ", $inputnot);

$aantalwrd = count($inputarray); //aantal woorden tellen
$count = -1;
while ($count < $aantalwrd -1) //Opent een while loop waarvan de commandos uitgevoerd worden totdat $count gelijk is aan het aantal woorden in de array.
{
$count++;
If ($count == 0){
$newarray[$count] = " like '%".$inputarray[$count]."%'"; //voor eerste woord in de zin like
}ELSE{
$newarray[$count] = " OR question like '%".$inputarray[$count]."%'";// voor andere woorden or like
}
}

for ($count = -1; $count < $aantalwrd -1; $count++)
{
$achterelkaar = $achterelkaar.$newarray[$count];// alles uit de array in 1 variabele stoppen
}



$query =(mysql_query('SELECT question FROM general WHERE question '.$achterelkaar.'')or die ( mysql_error( ))); //query uitvoeren
while($record = mysql_fetch_object($query)){
echo $record->question;

} //resultaten laten zien

//<META HTTP-EQUIV="refresh" content="10; url=index.php">

}
?>
</body>
</html>


hier is een voorbeeld van wat ik tot nu toe heb:

http://bot.pipobona.com/index.php


het werkt nog niet goed , als ik iets intyp bijvoorbeeld: where is the shop , dan echoéd hij niks , zelfs als ik letterlijk : where shop intyp doet hij niks.

wat doe ik fout? ik hoop dat jullie het antwoord weten

Je query klopt niet.

Dit:

'SELECT question FROM general WHERE question '.$achterelkaar.''

Moet zijn:

'SELECT question FROM general WHERE question = \'' . $achterelkaar . '\''
als ik het op die manier doe krijg ik deze error:

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 'where%' OR question like '%is%' OR question like '%the%' OR question like ' at line 1
('SELECT question FROM general WHERE = question '.$achterelkaar)

Zo zou het denk ik wel moeten werken...
Anders echo ik meestal de query. Het resultaat (ookal komt er `array` uit, je weet dat er dus resultaat is).
Dan kan je zien waar de fout zit...
ik zla het wel even echoén en het hier posten
hij geeft deze query wanneer ik : where is the shop ? intyp.

SELECT question FROM general WHERE question like '%where%' OR question like '%is%' OR question like '%the%' OR question like '%shop%'
Van mijn post moet je ook weinig aantrekken, had niet goed gekeken... Die variabele is een stuk query :$

En als je met haakjes gaat werken?

Dus WHERE
(question LIKE %where%) OR (question LIKE %the%) enz...

Weet niet of het werkt...

Edit:
Als je met LIKE en %'en werkt, moet je er dan wel >> ' << omheen zetten?
Als je strings gebruikt in je query, moet je die altijd tussen quotes zetten, ook als je wildcards als % en _ gebruikt.
SELECT question FROM general WHERE question like '%where%' OR question like '%is%' OR question like '%the%' OR question like '%shop%'

Als dit de echo van je query is, dan is die toch goed?
dan zit er ergens anders een fout in denk , want ik krijg geen resultaten op mijn beeldscherm

Reageren