View Single Post
Old 10-05-2007, 10:16 PM   #5 (permalink)
Tanax
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Okey, I got this to so that the JS at least shows up:

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" onkeyup="search(this.value)">
</form>

<p>
<div id="txtHint"><b>You can search for guilds, players, levels and vocations!</b></div>
</p>

</body>
</html>
Code:
var xmlHttp

function search(str) { 
	
	xmlHttp=GetXmlHttpObject()
	
	if (xmlHttp==null) {
 
 		alert ("Browser does not support HTTP Request")
 
 		return
 
 	}
 	
	var url="search.php"
	url=url+"?keyword="+str
	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("txtHint").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;
	
}
PHP Code:
<?php

include('config.php');
    
$get $_GET["keyword"];
    
    if (isset(
$get) && $get != "") {
        
        
$search urldecode($get);
        
        
$search $system->db->makesafe($search);
        
        
        
$pSql sprintf("SELECT * FROM %1$s WHERE name LIKE %s OR level LIKE %s OR vocation LIKE %s",
        
$table['players'],
        
'%'.$search.'%',
        
'%'.$search.'%',
        
'%'.$search.'%');    
        
$pResult $system->db->query($pSql);
        
        
        
$gSql sprintf("SELECT * FROM %s WHERE name LIKE %s"
        
$table['guilds'],
        
'%'.$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 
"<strong>Search again?</strong>";
        
    } 
    
?>
However, it gives me this error msg:

Quote:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\DB Class\search.php on line 33
Players:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\DB Class\search.php on line 61
Found results.


Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\DB Class\search.php on line 65
Guilds:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\DB Class\search.php on line 94
Found results.
Tanax is offline  
Reply With Quote