Jump to content

help with query


EchoFool

Recommended Posts

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
Share on other sites

You want:

SELECT eventtable.EventID 
FROM eventtable
LEFT JOIN usereventtable ON ( eventtable.EventID = usereventtable.EventID AND usereventtable.UserID='{$_SESSION['Current_User']}' )
WHERE eventtable.ActivateUrl='$Url' AND usereventtable.EventID IS NULL ORDER BY RAND() LIMIT 1

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.