phorcon3 Posted February 21, 2008 Share Posted February 21, 2008 I wanna do a search on three or more tables at once, but how would I do this? here's a mysql sample: CREATE TABLE `table1` ( `id` int(11) NOT NULL auto_increment, `col1` varchar(255) NOT NULL default '', `col2` varchar(255) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=1; CREATE TABLE `table2` ( `id` int(11) NOT NULL auto_increment, `col1` varchar(255) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=1; CREATE TABLE `table3` ( `id` int(11) NOT NULL auto_increment, `col1` varchar(255) NOT NULL default '', `col2` varchar(255) NOT NULL default '', `col3` varchar(255) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=1; so, what I need to do is: a) find the total number of results, so I suppose I will have to use Count(*) as Count somewhere? and b) find out from which table I got the current results php script: <?php $search = addslashes($_GET['search']); $a = mysql_query("");//query -> ex: SELECT on.col1, on.col2, tw.col1, tr.col1, tr.col2, tr.col3 FROM table1 as on, table1 as tw, table3 as tr WHERE on.col1 LIKE '%$search%' OR on.col2 LIKE '%$search%' etc. ORDER BY id DESC LIMIT 0,10 while($b = mysql_fetch_assoc($a)) { //find out from which table! echo 'this result is from table => '.$tablename; } echo 'the total search result is: '.$total; ?> Quote Link to comment Share on other sites More sharing options...
phorcon3 Posted February 21, 2008 Author Share Posted February 21, 2008 no ideas? or it doesnt make sense what im tryin to do? lol 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.