cpharry Posted April 25, 2009 Share Posted April 25, 2009 How do i split up the search results from the different tables because if i have two results both with the id 1 when the user clicks on the link which uses the id to get the data from the table it will get confused, so how do i split the results up into say an echoed table for the different tabled results if that makes sense. Character Result Table ---------------------------- Character result id 1 Location Result Table --------------------------- Location result id 1 And currently whenever i search for something the entire two tables just echo all the data in them from the name column not what i searched for. <? $search = $_POST["search"]; $connection = mysql_connect("localhost","wowbasec","PASSWORD REMOVED"); mysql_select_db("wowbasec_class", $connection); $query = "select * from characters, location WHERE characters.name='$search' or location.name='$search' "; $result = mysql_query($query, $connection); if (!$result) { echo 'Invalid query: ' . mysql_error(). "<br>"; echo 'SQL Query: ' . $query. "<br>"; die(); } while ($r = mysql_fetch_assoc($result)) { // Begin while $ts = $r["name"]; ?> <table width="1000" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><a href="view.php?id=<?php echo $r['id'];?>"> <? echo $r['name'] ?></td> </tr> </table> <? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/155614-splitting-results-up/ Share on other sites More sharing options...
gaza165 Posted April 25, 2009 Share Posted April 25, 2009 You could always run two different queries?? Quote Link to comment https://forums.phpfreaks.com/topic/155614-splitting-results-up/#findComment-819037 Share on other sites More sharing options...
fenway Posted April 27, 2009 Share Posted April 27, 2009 You need to use UNION... not a JOIN. Quote Link to comment https://forums.phpfreaks.com/topic/155614-splitting-results-up/#findComment-819974 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.