EchoFool Posted June 12, 2008 Share Posted June 12, 2008 I have two tables like so: Usereventtable (in this case has no rows) UserID | EventID | Complete | and eventtable (has one row) EventID | ActivateUrl | Other random fields unrelated to this 1 bleh.php etc etc etc What i am trying to do is, collect all the rows which are found in eventtable but no in usereventtable related to a userID and then pick a random row from that select. How ever it should be finding one row as I purposely put a dummy row in to make sure it works but my mysql_num_rows says it is not finding any row. My code: <?php $Find = mysql_query("SELECT eventtable.EventID FROM eventtable,usereventtable WHERE eventtable.ActivateUrl='$Url' AND eventtable.EventID != usereventtable.EventID AND usereventtable.UserID='{$_SESSION['Current_User']}' ORDER BY RAND() LIMIT 1") Or die(mysql_error()); If(mysql_num_rows($Find)<1){ Echo 'failure, check query'; }Else{ Echo 'woo!!'; } ?> What have I done wrong? Link to comment https://forums.phpfreaks.com/topic/109941-help-with-query-issue/ Share on other sites More sharing options...
phpzone Posted June 12, 2008 Share Posted June 12, 2008 <?php $Find = mysql_query("SELECT eventtable.EventID FROM eventtable,usereventtable WHERE eventtable.ActivateUrl='$Url' AND eventtable.EventID != usereventtable.EventID AND usereventtable.UserID='{$_SESSION['Current_User']}' ORDER BY RAND() LIMIT 1") Or die(mysql_error()); If(mysql_num_rows($Find)<1){ Echo 'failure, check query'; }Else{ Echo 'woo!!'; } ?> I'm no SQL expert, but in the absence of any other replies, try something like this if your server support Sub Selects... or ask in an SQL/Database forum SELECT eventtable.EventID FROM eventtable WHERE eventtable.EventID NOT IN ( SELECT usereventtable.EventID FROM usereventtable WHERE usereventtable.UserID='{$_SESSION['Current_User']}' ) AND eventtable.ActivateUrl='$Url' ORDER BY RAND() LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/109941-help-with-query-issue/#findComment-564193 Share on other sites More sharing options...
EchoFool Posted June 12, 2008 Author Share Posted June 12, 2008 Ill re-post in the mysql section if some one could delete this thread as to avoid duplicates. Link to comment https://forums.phpfreaks.com/topic/109941-help-with-query-issue/#findComment-564291 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.