-Karl- Posted March 20, 2010 Share Posted March 20, 2010 I have my code: <?php if (isset($_GET['search'])) { echo <<<HTML <center>You searched for {$_GET['search']}</center> HTML; if(strlen($_GET['search']) <= 3){ echo 'Search must contain more than 3 characters.'; } else { $con = mysql_connect("localhost","****","****"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("****", $con); // Collect guides $query = "SELECT * FROM `news` WHERE (`id` LIKE '%{$_GET['search']}%' OR `title` LIKE '%{$_GET['search']}%' OR `thumb` LIKE '%{$_GET['search']}%' OR `news` LIKE '%{$_GET['search']}%' OR `postedby` LIKE '%{$_GET['search']}%')"; $run = mysql_query($query); if(!mysql_num_rows($run)==0){ if($run){ while($arr = mysql_fetch_assoc($run)){ echo <<<HTML <font color="blue">{$arr['title']}</font><br/> <font color="white">{$arr['news']}</font><br/> <a href="#">{$arr['id']}</a><br/><br/><br/> HTML; } } } if(mysql_num_rows($run)==0){ echo 'No results found'; } } } ?> But at the moment it only searches the "news" table, and only columns specific to that table (id, title, thumb, etc). However, I have around 4 tables, with unique columns in each one. I need to change the MySQL query to search each of the tables and the columns in each one, then output the data. I'm not sure how to do this though as I've never tried any joining, or union based queries before. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/195924-searching-multiple-tables-and-rows/ Share on other sites More sharing options...
jskywalker Posted March 20, 2010 Share Posted March 20, 2010 joins: http://www.w3schools.com/sql/sql_join.asp unions: http://www.w3schools.com/sql/sql_union.asp read both pages, and if you still have a question, ask.... Link to comment https://forums.phpfreaks.com/topic/195924-searching-multiple-tables-and-rows/#findComment-1029177 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.