TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 10-05-2007, 06:42 PM   #1 (permalink)
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 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.
Tanax is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 04:13 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design