imperium2335 Posted May 15, 2011 Share Posted May 15, 2011 Hi, Is there a more efficient way of doing this? $result = mysql_query("SELECT users.id FROM users, active_users_dyn WHERE users.id = active_users_dyn.userRef AND users.username = '$user' LIMIT 1")or die(mysql_error()) ; $result2 = mysql_query("SELECT users.id FROM users WHERE users.isRegistered = 1 AND users.username = '$user' LIMIT 1")or die(mysql_error()) ; $errz = mysql_num_rows($result) + mysql_num_rows($result2) ; I have tried combining them into one query using another set of ANDS with an OR but it brings back 0 rows even though I know there is one. Also, since I'm only interested in the number of rows, do I have to SELECT something even though I don't need it? Link to comment https://forums.phpfreaks.com/topic/236484-combined-query-not-working/ Share on other sites More sharing options...
Zane Posted May 15, 2011 Share Posted May 15, 2011 SELECT users.id FROM users JOIN active_users_dyn as dyn ON users.id = dyn.userRef WHERE users.username = '$user' AND users.isRegistered = 1 Link to comment https://forums.phpfreaks.com/topic/236484-combined-query-not-working/#findComment-1215773 Share on other sites More sharing options...
imperium2335 Posted May 15, 2011 Author Share Posted May 15, 2011 Thanks, but it didn't work Same result as: $result = mysql_query("SELECT users.id FROM users, active_users_dyn WHERE users.id = active_users_dyn.userRef AND users.username = '$user' OR users.isRegistered = 1 AND users.username = '$user' LIMIT 1")or die(mysql_error()) ; Saying there are no rows. Link to comment https://forums.phpfreaks.com/topic/236484-combined-query-not-working/#findComment-1215776 Share on other sites More sharing options...
Zane Posted May 15, 2011 Share Posted May 15, 2011 What does this pull up? SELECT users.id FROM users JOIN active_users_dyn as dyn ON users.id = dyn.userRef WHERE users.username = '$user' Link to comment https://forums.phpfreaks.com/topic/236484-combined-query-not-working/#findComment-1215784 Share on other sites More sharing options...
imperium2335 Posted May 15, 2011 Author Share Posted May 15, 2011 0 rows Link to comment https://forums.phpfreaks.com/topic/236484-combined-query-not-working/#findComment-1215791 Share on other sites More sharing options...
Zane Posted May 15, 2011 Share Posted May 15, 2011 Well then $user must not have the value you think it does To find out you can either run this query SELECT users.id FROM users WHERE users.username = '$user' Or echo out the $user variable and see for yourself. Link to comment https://forums.phpfreaks.com/topic/236484-combined-query-not-working/#findComment-1215794 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.