Help with query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Snobbery08
Forum Newbie
Posts: 13
Joined: Sun Jan 06, 2008 10:45 am

Help with query

Post by Snobbery08 »

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 not in usereventtable related to a userID and then pick a random row from that selection.

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:

Code: Select all

<?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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Help with query

Post by Christopher »

SELECT ... FROM eventtable JOIN usereventtable ON eventtable.eventID=usereventtable.eventID WHERE ...
(#10850)
Post Reply