10-06-2007, 04:00 PM
|
#8 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Quote:
Originally Posted by Karl
After a quick look through (literally 2 mins) I would guess that the error is coming from your mix of $pResult and $gResult, surely they are both supposed to be the same?
Another suggestion would be to take a look at Prototype JS it'll make things so much easier for you. With it, you could easily cut down your Ajax Search JavsScript file to a few lines of code split between a few functions.
|
Yea, but sorry, I don't know anything about Prototype JS ://
Quote:
Originally Posted by Salathe
Your SELECT queries are not valid SQL since the values used in the LIKE statements are not delimited by quotation marks. Both queries have the same issue which needs to be fixed.
For example:
PHP Code:
// Wrong: SELECT * FROM table WHERE name LIKE search_term $gSql = sprintf("SELECT * FROM %s WHERE name LIKE %s", // Right: SELECT * FROM table WHERE name LIKE 'search_term' $gSql = sprintf("SELECT * FROM %s WHERE name LIKE '%s' ",
|
Thanks! I got it to work now without any PHP errors.
However, I got this:
Quote:
Players:
Found 1 results.
Result Name Level Vocation Profile
1
Account Manager
1
0
Link
Guilds:
Found 1 results.
|
As you see, it finds 1 result from the players, and it prints the result in a table. But it also finds a result from the guilds, but it doesn't print it :S
And this is only got to do with the PHP script, so here it is:
PHP Code:
<?php
/** |||||||||||||||||||||||||||||||||||||||||| |||| @author Tanax |||| @copyright 2007 |||||||||||||||||||||||||||||||||||||||||| **/
include('config.php'); $get = $_GET["keyword"]; if (isset($get) && $get != "") { // Make the searchvalue safe from injections $search = urldecode($get); $search = $system->db->makesafe($search); // Search for players $pSql = sprintf("SELECT * FROM %s WHERE name LIKE '%s' OR level LIKE '%s' OR vocation LIKE '%s'", $table['players'], '%'.$search.'%', '%'.$search.'%', '%'.$search.'%'); $pResult = $system->db->query($pSql); // Search for guilds $gSql = sprintf("SELECT * FROM %s WHERE name LIKE '%s'", $table['guilds'], '%'.$search.'%'); $gResult = $system->db->query($gSql); // Check if the player search returned any results if (mysql_num_rows($pResult) != 0) { // Echoes the table echo '<h1>Players:</h1>'; echo '<div id="smalltext">Found ' .mysql_num_rows($pResult). ' results.</div><br />'; echo '<table border="1" width="500"><tr>'; echo '<th>Result</th>'; echo '<th>Name</th>'; echo '<th>Level</th>'; echo '<th>Vocation</th>'; echo '<th>Profile</th></tr>'; for ($i = 1; $player = mysql_fetch_object($pResult); $i++) { echo '<tr>'; echo '<td><center>' .$i. '</center></td>'; echo '<td><center>' .$player->name. '</center></td>'; echo '<td><center>' .$player->level. '</center></td>'; echo '<td><center>' .$player->vocation. '</center></td>'; echo '<td><center><a href="account.php?name=' .$player->name. '">Link</a></center></td>'; echo '</tr>'; } echo '</table>'; } else { echo '<h1>Players:</h1>'; echo '<div id="smalltext">Found ' .mysql_num_rows($pResult). ' results.</div><br />'; } // Check if the guild search returned any results if (mysql_num_rows($gResult) != 0) { // Echoes the table echo '<h1>Guilds:</h1>'; echo '<div id="smalltext">Found ' .mysql_num_rows($gResult). ' results.</div><br />'; echo '<table border="1" width="500"><tr>'; echo '<th>Result</th>'; echo '<th>Name</th>'; echo '<th>Owner</th></tr>'; for ($i = 1; $guild = mysql_fetch_object($gResult); $i++) { // Get the name of the owner $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 />'; } } // If the search is empty else { echo "<strong>Search again?</strong>"; } ?>
|
|
|
|