Mijn db query script werkt niet goed
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:
<!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>
<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>
</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
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:
<!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>
<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>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?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">
}
?>
}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
Gesponsorde koppelingen:
Je query klopt niet.
Dit:
'SELECT question FROM general WHERE question '.$achterelkaar.''
Moet zijn:
'SELECT question FROM general WHERE question = \'' . $achterelkaar . '\''
Dit:
'SELECT question FROM general WHERE question '.$achterelkaar.''
Moet zijn:
'SELECT question FROM general WHERE question = \'' . $achterelkaar . '\''
Gewijzigd op 13/10/2005 23:47:00 door Martijn B
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
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...
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%'
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?
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?
Gewijzigd op 14/10/2005 14:25:00 door Willem Jan Z
tsja , ik ben daar niet zo ervaren mee , ik heb hier een beetje gekeken:
http://designhulp.nl/forum/programmeren/php/4730/1
http://designhulp.nl/forum/programmeren/php/4730/1
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?
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
En hij geeft geen error?
nee
SELECT question FROM general WHERE question like '%where%' OR question like '%is%' OR question like '%the%' OR question like '%shop%'
verander die query heel even in
SELECT question FROM general WHERE 1
en kijk eens of je dan wel output hebt.
verander die query heel even in
SELECT question FROM general WHERE 1
en kijk eens of je dan wel output hebt.
nee :S
Ligt het misschien aan de volledige regel?
Probeer eens
Dus zonder de extra ( en )
Code (php)
1
2
3
2
3
<?php
$query = (mysql_query("SELECT question FROM general WHERE question like '%where%' OR question like '%is%' OR question like '%the%' OR question like '%shop%'") or die ( mysql_error( ))); //query uitvoeren
?>
$query = (mysql_query("SELECT question FROM general WHERE question like '%where%' OR question like '%is%' OR question like '%the%' OR question like '%shop%'") or die ( mysql_error( ))); //query uitvoeren
?>
Probeer eens
Code (php)
1
2
3
2
3
<?php
$query = mysql_query("SELECT question FROM general WHERE question like '%where%' OR question like '%is%' OR question like '%the%' OR question like '%shop%'") or die (mysql_error()); //query uitvoeren
?>
$query = mysql_query("SELECT question FROM general WHERE question like '%where%' OR question like '%is%' OR question like '%the%' OR question like '%shop%'") or die (mysql_error()); //query uitvoeren
?>
Dus zonder de extra ( en )
dit krijg ik als ik de error reporting aanzet:
Notice: Undefined offset: -1 in /home/contracts/CN20050639/bot/index.php on line 54
Notice: Undefined variable: achterelkaar in /home/contracts/CN20050639/bot/index.php on line 54
Notice: Undefined offset: -1 in /home/contracts/CN20050639/bot/index.php on line 54
Notice: Undefined variable: achterelkaar in /home/contracts/CN20050639/bot/index.php on line 54
Gewijzigd op 14/10/2005 19:09:00 door Stefan
nadat ik deze fouten heb verbeterd doet hij het eindelijk !
heel erg bedankt voor al jullie hulp.
heel erg bedankt voor al jullie hulp.



