Mr.x Posted December 6, 2006 Share Posted December 6, 2006 Good Afternoon.Creating a user search and am having some issues with the sql queries.Search options areUsername 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 https://forums.phpfreaks.com/topic/29717-user-search-multiple-credentials-resolved/ Share on other sites More sharing options...
marcus Posted December 6, 2006 Share Posted December 6, 2006 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);}elseif(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);}elseif(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);}elseif(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);}elseif(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);}elseif(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);}elseif(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);}elseif(!$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 https://forums.phpfreaks.com/topic/29717-user-search-multiple-credentials-resolved/#findComment-136431 Share on other sites More sharing options...
Mr.x Posted December 6, 2006 Author Share Posted December 6, 2006 Thank you very much, really appreciate it!! :D Link to comment https://forums.phpfreaks.com/topic/29717-user-search-multiple-credentials-resolved/#findComment-136435 Share on other sites More sharing options...
marcus Posted December 6, 2006 Share Posted December 6, 2006 No problem Link to comment https://forums.phpfreaks.com/topic/29717-user-search-multiple-credentials-resolved/#findComment-136437 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.