Fenhopi Posted January 19, 2011 Share Posted January 19, 2011 Hi, I have this join query that's supposed to take the information from both tables, but it only takes from the commentstatus table, any idea why? Query: $GetStatus = "SELECT * FROM commentstatus, wallposts WHERE (commentstatus.status='$Naw' AND commentstatus.person='$username') OR (wallposts.stat='$Naw' AND wallposts.person='$username')"; Quote Link to comment https://forums.phpfreaks.com/topic/224942-problems-with-a-join-query/ Share on other sites More sharing options...
suresh_kamrushi Posted January 19, 2011 Share Posted January 19, 2011 Hey Fenhopi , You can try this, as still I am not sure about your table relations. If this query does not work please provide table structure with their relation so that we can map it accorindly to fetch the correct records. $GetStatus = "SELECT * FROM commentstatus, wallposts WHERE (commentstatus.status='$Naw' AND wallposts.stat='$Naw') OR (commentstatus.person='$username' AND wallposts.person='$username')"; Quote Link to comment https://forums.phpfreaks.com/topic/224942-problems-with-a-join-query/#findComment-1161808 Share on other sites More sharing options...
Fenhopi Posted January 19, 2011 Author Share Posted January 19, 2011 Thanks, but it didn't work. Here's table structure: CREATE TABLE `wallposts` ( `postid` int(11) NOT NULL AUTO_INCREMENT, `message` varchar(1000) DEFAULT NULL, `byuser` varchar(25) DEFAULT NULL, `dtime` varchar(50) DEFAULT NULL, `stat` int(11) DEFAULT NULL, `person` varchar(25) DEFAULT NULL, PRIMARY KEY (`postid`) ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 CREATE TABLE `commentstatus` ( `commentid` int(11) NOT NULL AUTO_INCREMENT, `shairid` int(11) NOT NULL, `message` varchar(250) DEFAULT NULL, `byuser` varchar(50) DEFAULT NULL, `dtime` varchar(50) DEFAULT NULL, `person` varchar(50) NOT NULL, `status` int(4) DEFAULT NULL, PRIMARY KEY (`commentid`) ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 Quote Link to comment https://forums.phpfreaks.com/topic/224942-problems-with-a-join-query/#findComment-1161816 Share on other sites More sharing options...
Muddy_Funster Posted January 19, 2011 Share Posted January 19, 2011 couple of things. why are you selecting * ? do you actualy need all the fields from both the tables? you didn't state what the connection between the tables was and you have no forign keys listed. Does commentstatus.shairid = wallposts.postid ? max size for a varchar field should be 255, that you were able to create that table with a value of 1000 is a bit surprising. if you want a field that size you need to use TEXT(1000). can you let us know what you want out of each of the tables as well as how they relate to each other so we can better help create the query? Quote Link to comment https://forums.phpfreaks.com/topic/224942-problems-with-a-join-query/#findComment-1161822 Share on other sites More sharing options...
fenway Posted January 22, 2011 Share Posted January 22, 2011 max size for a varchar field should be 255, that you were able to create that table with a value of 1000 is a bit surprising. if you want a field that size you need to use TEXT(1000). Not true at all. VARCHAR can be up to 65,535 in version 5 -- and it's much better to use this than TEXT -- which, by the way, has no "size". Quote Link to comment https://forums.phpfreaks.com/topic/224942-problems-with-a-join-query/#findComment-1163729 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.