phorcon3 Posted April 5, 2008 Share Posted April 5, 2008 i'm trying to find out from which table the results are from so, for example i have these two mysql tables: CREATE TABLE `table_1` ( `id` int(11) NOT NULL auto_increment, `text` varchar(255) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=1; CREATE TABLE `table_2` ( `id` int(11) NOT NULL auto_increment, `text` varchar(255) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=1; and now i wanna create a search query: <?php $search = addslashes($_GET['search']); $a = mysql_query("SELECT o.id, o.text, s.id, s.text FROM table_1 AS o, table_2 AS s WHERE (o.text LIKE '%$search%' OR s.text LIKE '%$search%')"); while($b = mysql_fetch_assoc($a)) { //and here i wanna check ..is the text that is bein displayed from table_1 or table_2? echo $b['text']; } ?> that won't work would it? i would need different primary keys, right? for example `oid` int(11) NOT NULL auto_increment, and `sid` int(11) NOT NULL auto_increment, or could it work the way i was tryin to do it? any help is appreciated. Link to comment https://forums.phpfreaks.com/topic/99751-search-query/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.