Mr Chris Posted October 20, 2009 Share Posted October 20, 2009 Hi, I'm trying to do a Query with a Union where I want to print the number of rows $tc contains. Can anyone see what's wrong with this: $tc = @mysql_num_rows(mysql_query("(SELECT * FROM tbl1 WHERE id = $id) UNION (SELECT * FROM tbl2 WHERE id = $id)")); print $tc; Quote Link to comment https://forums.phpfreaks.com/topic/178373-solved-help-with-simple-query/ Share on other sites More sharing options...
sasa Posted October 20, 2009 Share Posted October 20, 2009 remove @from begining and look the error Quote Link to comment https://forums.phpfreaks.com/topic/178373-solved-help-with-simple-query/#findComment-940625 Share on other sites More sharing options...
janusmccarthy Posted October 20, 2009 Share Posted October 20, 2009 Is this a trick question? Are you getting an error? I can't see anything wrong with it off the top of my head, but you could have written it and tested in the time it takes to post here so I'm not sure why it's here. If you are getting an error, separate out the statements: print "QUERY STRING: "."(SELECT * FROM tbl1 WHERE id = $id) UNION (SELECT * FROM tbl2 WHERE id = $id)"; print "QUERY RESULT: ".mysql_query("(SELECT * FROM tbl1 WHERE id = $id) UNION (SELECT * FROM tbl2 WHERE id = $id)"); print "COUNT RESULT: ".mysql_num_rows(mysql_query("(SELECT * FROM tbl1 WHERE id = $id) UNION (SELECT * FROM tbl2 WHERE id = $id)")); Quote Link to comment https://forums.phpfreaks.com/topic/178373-solved-help-with-simple-query/#findComment-940628 Share on other sites More sharing options...
Baronen Posted October 20, 2009 Share Posted October 20, 2009 Without an error it's hard But make sure tbl1 and tbl2 has the same number of columns, this is required because you select * Quote Link to comment https://forums.phpfreaks.com/topic/178373-solved-help-with-simple-query/#findComment-940631 Share on other sites More sharing options...
Mr Chris Posted October 20, 2009 Author Share Posted October 20, 2009 Cheers Guys, I'll investigate further Quote Link to comment https://forums.phpfreaks.com/topic/178373-solved-help-with-simple-query/#findComment-940633 Share on other sites More sharing options...
Mr Chris Posted October 20, 2009 Author Share Posted October 20, 2009 My Bad - column count did not match! Quote Link to comment https://forums.phpfreaks.com/topic/178373-solved-help-with-simple-query/#findComment-940648 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.