Jump to content

User search, multiple credentials. - RESOLVED


Mr.x

Recommended Posts

Good Afternoon.

Creating a user search and am having some issues with the sql queries.

Search options are

Username Contains : (Input)
Location : (Input)
Age Minimum (Input) Maximum (Input)

I need it so if they only enter a username it finds that username, or if they only enter a location it finds everyone in that location.

But I also need it so if they enter a location and age, it only retrieves people who are that age and live there. etc.

Thanks in advance,
Sean.
Link to comment
Share on other sites

i did not test this, so there might be errors

[code]
<?php
$uname = $_POST[username];
$locate = $_POST[location];
$age = $_POST[age];

if(isset($uname) && !$locate && !$age){
$sql = "SELECT * FROM `users` WHERE username LIKE '$uname'";
$res = mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_assoc($res)){
echo "<a href=page.php?username=$row[username]>$row[username]</a><br><br>";
}
mysql_free_result($res);
}else

if(isset($uname) && isset($locate) && !$age){
$sql = "SELECT * FROM `users` WHERE username LIKE '$uname' AND location LIKE '$locate'";
$res = mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_assoc($res)){
echo "<a href=page.php?username=$row[username]>$row[username] in $row[location]</a><br><br>";
}
mysql_free_result($res);
}else

if(isset($uname) && isset($locate) && isset($age)){
$sql = "SELECT * FROM `users` WHERE username LIKE '$uname' AND location LIKE '$locate' AND age =$age";
$res = mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_assoc($res)){
echo "Age: $row[age] <a href=page.php?username=$row[username]>$row[username] in $row[location]</a>";
}
mysql_free_result($res);
}else

if(isset($uname) && isset($age) && !$locate){
$sql = "SELECT * FROM `users` WHERE username LIKE '$uname' AND age =$age";
$res = mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_assoc($res)){
echo "Age: $row[age] <a href=page.php?username=$row[username]>$row[username]</a>";
}
mysql_free_result($res);
}else
if(isset($locate) && isset($age) && !$uname){
$sql = "SELECT * FROM `users` WHERE location LIKE '$locate' AND age =$age";
$res = mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_assoc($res)){
echo "Age: $row[age] <a href=page.php?username=$row[username]>$row[username] in $row[location]</a><br><br>";
}
mysql_free_result($res);
}else
if(isset($locate) && !$age && !$uname){
$sql = "SELECT * FROM `users` WHERE location LIKE '$locate'";
$res = mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_assoc($res)){
echo "<a href=page.php?username=$row[username]>$row[username] in $row[locate]</a>"
}
mysql_free_result($res);
}else

if(isset($age) && !$locate && !$uname){
$sql = "SELECT * FROM `users` WHERE age =$age";
$res = mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_assoc($res)){
echo "Age: $row[age] <a href=page.php?username=$row[username]>$row[username]</a><br><br>";
}
mysql_free_result($res);
}else

if(!$locate && !$age && !$uname){
echo "<form name=find method=post action=searchuser.php>\n";
echo "username: <input type=text name=username>\n";
echo "location: <input type=text name=location>\n";
echo "age: <input type=text name=age>\n";
echo "<input type=submit value=search>\n";
echo "</form>";
};
?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.