10-05-2007, 06:42 PM
|
#1 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Need your feedback
Yea, this isn't working.. no idea why.
search.html
HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta name="author" content="Tanax">
<script src="AJAXsearch.js"></script>
<title>Search</title>
</head>
<body>
<h1>Search:</h1>
<form>
<input type="text" name="search" onkeyup="search(this.value)">
</form>
<p>
<div id="results"><b>You can search for guilds, players, levels and vocations!</b></div>
</p>
</body>
</html>
AJAXsearch.js
Code:
var xmlHttp
function search(string) {
xmlHttp = GetXmlHttpObject()
if(xmlHttp == null) {
alert("Your browser does not support HTTP requests!")
return
}
var url = "search.php"
var url = url+"?keyword="+str
var url = url+"&sid="+Math.random()
xmlHttp.onreadystatechange = stateChanged
xmlHttp.open("GET", url, true)
xmlHttp.send(null)
}
function stateChanged() {
if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
document.getElementById("results").innerHTML = xmlHttp.responseText
}
}
function GetXmlHttpObject() {
var xmlHttp = null
try {
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest()
}
catch (e) {
//Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
}
}
return xmlHttp
}
search.php
PHP Code:
<?php
include('config.php');
$get = $_GET["keywords"];
if (isset($get) && $get != "") {
$search = urldecode($get);
$search = $system->db->makesafe($search);
$pSql = sprintf("SELECT * FROM ".$system->db->table['players']." WHERE name LIKE %1$s OR level LIKE %1$s OR vocation LIKE %1$s",
%$search%);
$pResult = $system->db->query($pSql);
$gSql = sprintf("SELECT * FROM ".$system->db->table['guilds']." WHERE name LIKE %s", %$search%);
$gResult = $system->db->query($gSql);
if (mysql_num_rows($pResult) != 0) {
echo '<h1>Players:</h1>';
echo '<div id="smalltext">Found ' .mysql_num_rows($pResult). ' results.</div><br />';
echo '<table><tr>';
echo '<td>Result</td>';
echo '<td>Name</td>';
echo '<td>Level</td>';
echo '<td>Vocation</td></tr>';
for ($i = 1; $player = mysql_fetch_object($pResult); $i++) {
echo '<tr>';
echo '<td>' .$i. '</td>';
echo '<td>' .$player->name. '</td>';
echo '<td>' .$player->level. '</td>';
echo '<td>' .$player->vocation. '</td>';
echo '</tr>';
}
echo '</table>';
}
else {
echo '<h1>Players:</h1>';
echo '<div id="smalltext">Found ' .mysql_num_rows($pResult). ' results.</div><br />';
}
if (mysql_num_rows($gResult) != 0) {
echo '<h1>Guilds:</h1>';
echo '<div id="smalltext">Found ' .mysql_num_rows($gResult). ' results.</div><br />';
echo '<table><tr>';
echo '<td>Result</td>';
echo '<td>Name</td>';
echo '<td>Owner</td></tr>';
for ($i = 1; $guild = mysql_fetch_object($gResult); $i++) {
$system->player->load($guild->ownerid);
$name = $system->player->getName();
echo '<tr>';
echo '<td>' .$i. '</td>';
echo '<td>' .$guild->name. '</td>';
echo '<td>' .$name. '</td>';
echo '</tr>';
}
echo '</table>';
}
else {
echo '<h1>Guilds:</h1>';
echo '<div id="smalltext">Found ' .mysql_num_rows($pResult). ' results.</div><br />';
}
}
else {
echo "You can search for guilds, players, levels and vocations!";
}
?>
When I write something, NOTHING gets up :S
I haven't actually created the table players yet, but that shouldn't matter, it should change the results div message to a db error message in that case.
|
|
|
|