newhip Posted February 4, 2014 Share Posted February 4, 2014 Ok if have some code that i am trying to add to. <form action="#" method="post" enctype="multipart/form-data"> <input type="text" name="search"/> <input type="submit" name="search1"/> </form> <?php if(isset($_POST['search1'])){ $search=mysql_real_escape_string($_POST['search']); } include 'connect.php'; if(isset($_POST['search1'])){ $query=mysql_query("SELECT * FROM media WHERE extra_cred LIKE '%".$search."%' OR artist_id LIKE '%".$search."%' OR title LIKE '%".$search."%' OR content LIKE '%".$search."%' OR detail LIKE '%".$search."%' OR tags LIKE '%".$search."%' OR user LIKE '%".$search."%' OR type LIKE '%".$search."%' ") ?> What I would like to do is also search another table within that database by the name of artists with the same POST data. Anyone know what to do? I've been at this for a while. Link to comment https://forums.phpfreaks.com/topic/285921-search-2-tables-at-once/ Share on other sites More sharing options...
jazzman1 Posted February 4, 2014 Share Posted February 4, 2014 Is there a relationship between both tables? Do DESCRIBE to provide more information about tables structure. If there is no relationship between these two tables you can consider using an UNION query. Also, never use the dreaded, evil "select star" in your queries in the future. It's a very, very bad practice. Link to comment https://forums.phpfreaks.com/topic/285921-search-2-tables-at-once/#findComment-1467689 Share on other sites More sharing options...
newhip Posted February 4, 2014 Author Share Posted February 4, 2014 Well there is sort of a relationship. The artist_id field is the primary id field in the artist table. Link to comment https://forums.phpfreaks.com/topic/285921-search-2-tables-at-once/#findComment-1467710 Share on other sites More sharing options...
jazzman1 Posted February 4, 2014 Share Posted February 4, 2014 I think you didn't understand very proper my question about the relationship between those two tables. So, could you shows us the results of: DESCRIBE media; and DESCRIBE artists; Link to comment https://forums.phpfreaks.com/topic/285921-search-2-tables-at-once/#findComment-1467730 Share on other sites More sharing options...
Barand Posted February 4, 2014 Share Posted February 4, 2014 Use a join on artist_id $query=mysql_query("SELECT m.*, a.artist_name FROM media m JOIN artist a USING (artist_id) WHERE extra_cred LIKE '%".$search."%' OR artist_name LIKE '%$search%' OR m.artist_id LIKE '%".$search."%' OR title LIKE '%".$search."%' OR content LIKE '%".$search."%' OR detail LIKE '%".$search."%' OR tags LIKE '%".$search."%' OR user LIKE '%".$search."%' OR type LIKE '%".$search."%' "); Link to comment https://forums.phpfreaks.com/topic/285921-search-2-tables-at-once/#findComment-1467765 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.