Page 1 of 1

[HELP] Search Function

Posted: Tue Jan 22, 2013 3:11 pm
by srachit
So I am trying to make a search function for my game and I was wondering if anyone could help me out with it, I am a bit lost (I had the logic behind it one min, I lost it the next :/)

Here is what I have till now

Code: Select all

<center>
<form method= "POST" action = "search.php">
 Search by username: <input type="text" name="sname" size="21"><br>
 Search by nation name: <input type="text" name="nname" size = "21"><br>
 <input type="submit" name="submit" value="submit">
 </form>
</center>

<?php 

if(isset($_POST["submit"]))
{
	$oplayer = $_POST["sname"];
	$nname = $_POST["nname"];
	$oplayer = strip_tags($oplayer);
	$nname = strip_tags($nname);

	if($oplayer)
	{
		$query = "select name from players where name='$oplayer'";
		$result = mysql_query($query) or die("Could not query table");
		$result1 = mysql_fetch_array($result);
		if($result1)
		{
			if(isset($_GET['nation']))
			{$nation = $_GET['nation'];}
			else{$nation = $oplayer;}
		}
}
}
?>

Re: [HELP] Search Function

Posted: Thu Jan 24, 2013 12:05 pm
by alexrules01
Can't see a problem with it. Are you setting the $_GET['nation']?
Test each if statement and figure out which one isn't working and then work on it from there.

Re: [HELP] Search Function

Posted: Sat Jan 26, 2013 4:20 am
by Jackolantern
Yes, what exactly is the problem? What is it doing or not doing?

Re: [HELP] Search Function

Posted: Sat Jan 26, 2013 7:39 am
by srachit
Its pretty much not doing anything at all :P
How do I get my nations page to point at the user searched for and not point at my profile?

Re: [HELP] Search Function

Posted: Thu Feb 21, 2013 6:17 am
by alexrules01
From the code above, you are querying the database and trying to retrieve the data in the 'name' column where the username, or, 'oname' matches a value in the name column of the database. And then within the if statement, you are checking if $_GET['nation'] is set.
Can you give more details on what your trying to do? A step by step walkthrough? I'm stumped lol

Re: [HELP] Search Function

Posted: Thu Feb 21, 2013 12:50 pm
by Chris

Code: Select all

SELECT name FROM players WHERE name LIKE '%$oplayer%'
OR

Code: Select all

SELECT name FROM players WHERE MATCH (name) AGAINST ($oplayer)