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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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; Quote Link to comment Share on other sites More sharing options...
Barand Posted February 4, 2014 Share Posted February 4, 2014 (edited) 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."%' "); Edited February 4, 2014 by Barand Quote Link to comment 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.