vomitbomb Posted May 14, 2008 Share Posted May 14, 2008 At the moment I have to type in the full (exact) last name of an order to access it. Say if an order was for russel and another for rusker, I'd like to be able to type rus and have both orders come up. I am trying to find out how to do this so I can then have multiple results displayed and I can click on the right one. (in the case 2 or more people share the same last name) as you can imagine this can cause serious problems :| Here is my search query, any information is appreciated. //creating query $sql = "SELECT * FROM orders WHERE lname LIKE '$search'"; $result = mysql_query($sql, $conn); $row = mysql_fetch_array( $result ); Link to comment https://forums.phpfreaks.com/topic/105564-solved-returning-multiple-results-from-a-search-query/ Share on other sites More sharing options...
conker87 Posted May 14, 2008 Share Posted May 14, 2008 $sql = "SELECT * FROM orders WHERE lname LIKE '%$search%'"; Link to comment https://forums.phpfreaks.com/topic/105564-solved-returning-multiple-results-from-a-search-query/#findComment-540760 Share on other sites More sharing options...
vomitbomb Posted May 14, 2008 Author Share Posted May 14, 2008 Cool that solves me having to type in the exact name. Just need to work out how I can return multiple results. Thanks. Link to comment https://forums.phpfreaks.com/topic/105564-solved-returning-multiple-results-from-a-search-query/#findComment-540767 Share on other sites More sharing options...
vomitbomb Posted May 14, 2008 Author Share Posted May 14, 2008 Ok I've thought of a way to get to choose between multiple search results (ones with the same last name). I haven't been using $_GET but I thought this would be the easiest way. This code doesn't work, but any tips on how I can make it happen? just guessing this stuff. //create a query $sql = "SELECT * FROM orders WHERE lname LIKE '$search'"; $result = mysql_query($sql, $conn); while($row = mysql_fetch_array( $result )){ echo "<a href=showorders.php?searchf=$row['fname']searchl=$row['lname']>"; echo "".$row['fname']; echo "".$row['lname']; echo "</a>"; } Link to comment https://forums.phpfreaks.com/topic/105564-solved-returning-multiple-results-from-a-search-query/#findComment-540771 Share on other sites More sharing options...
vomitbomb Posted May 14, 2008 Author Share Posted May 14, 2008 This actually works, but only for the last name, how would I add a first name into the URL (I commented that out)? $sql = "SELECT * FROM orders WHERE lname LIKE '$search'"; $result = mysql_query($sql, $conn); while($row = mysql_fetch_array( $result )){ echo "<a href=showorders.php?search="; //echo "".$row['fname']; //echo "searchl="; echo "".$row['lname']; echo ">"; echo "".$row['fname']; echo "".$row['lname']; echo "<br>"; echo "</a>"; } Link to comment https://forums.phpfreaks.com/topic/105564-solved-returning-multiple-results-from-a-search-query/#findComment-540782 Share on other sites More sharing options...
conker87 Posted May 14, 2008 Share Posted May 14, 2008 $sql = "SELECT * FROM orders WHERE lname LIKE '$search'"; $result = mysql_query($sql, $conn); while($row = mysql_fetch_array( $result )){ echo "<a href='showorders.php?search=$row[fname]&searchl=$row[lname]'>$row[fname] $row[lname]</a><br>"; } Obviously, you'll have to incorporate more code if you want to search for the first name too. Link to comment https://forums.phpfreaks.com/topic/105564-solved-returning-multiple-results-from-a-search-query/#findComment-540785 Share on other sites More sharing options...
vomitbomb Posted May 14, 2008 Author Share Posted May 14, 2008 Cool it's parsing values like a champion now, next problem.. How do I use SELECT to search for 2 strings? :-\ ps. Here is the code I got working. $sql = "SELECT * FROM orders WHERE lname LIKE '$search'"; $result = mysql_query($sql, $conn); while($row = mysql_fetch_array( $result )){ echo "<a href=showorders.php?search="; echo "".$row['lname']; echo "&searchl="; echo "".$row['fname']; echo ">"; echo "".$row['fname']; echo "".$row['lname']; echo "<br>"; echo "</a>"; } and here is the code at the script it's being sent to. $search = $_GET['search']; $searchl = $_GET['searchl']; $sql = "SELECT * FROM orders WHERE lname LIKE '%$search%'"; I want this SELECT to use both $search and $searchl to get the exact result. Thanks Conker, your code is much nicer. But I'm pretty happy with my working mess Link to comment https://forums.phpfreaks.com/topic/105564-solved-returning-multiple-results-from-a-search-query/#findComment-540797 Share on other sites More sharing options...
conker87 Posted May 14, 2008 Share Posted May 14, 2008 You want to search for both the last name and first name? $sql = "SELECT * FROM orders WHERE lname LIKE '%$search%' AND fname LIKE '%$search1%'"; Link to comment https://forums.phpfreaks.com/topic/105564-solved-returning-multiple-results-from-a-search-query/#findComment-540803 Share on other sites More sharing options...
vomitbomb Posted May 14, 2008 Author Share Posted May 14, 2008 awesome, been trying to find the syntax for SELECT. and it's as easy as that, thanks conker! Link to comment https://forums.phpfreaks.com/topic/105564-solved-returning-multiple-results-from-a-search-query/#findComment-540810 Share on other sites More sharing options...
conker87 Posted May 14, 2008 Share Posted May 14, 2008 It's a pleasure. Link to comment https://forums.phpfreaks.com/topic/105564-solved-returning-multiple-results-from-a-search-query/#findComment-540812 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.