Jump to content

[SOLVED] Query Help


Intervelopment

Recommended Posts

Good Morning,

 

I have a bit of an issue with a script im writing and would really appreciate some help.

 

I have 2 tables, the first table has id, question_id, email_address and timestamp.

 

The second table has question_id and question.

 

What i need to be able to do, is get all the question_id's from the first table where the email address is lets say test@test.com

 

Then i need to search through the second table to find a random question with a question_id that is not listed in the results from the first query and print it out.

 

I have been looking around for quite some time but cannot seem to nail it.

 

If anyone could help, that would be greatly appreciated.

 

Cheers

Link to comment
Share on other sites

Something like this should do it:

 

$sql = "SELECT question FROM table2 WHERE question_id NOT IN (SELECT question_id FROM table1 WHERE emailaddress = 'test@test.com') ORDER BY RAND() LIMIT 1";
$result = mysql_query($sql);
echo $row['question'];

Link to comment
Share on other sites

Its not echoing anything out :(

 

This is what i put.

 

					    function dispQuestion(){
				        global $database, $session;
				        
				        $email = $session->usremail;
				        $q = "SELECT question FROM ".TBL_QUESTIONS." WHERE question_id NOT IN (SELECT question_id FROM ".TBL_DONE_QUESTIONS." WHERE email = '$email') ORDER BY RAND() LIMIT 1";
				        $result = $database->query($q);
				        
				        echo $row['question'];
				    }

 

One thing i did pick up in TBL_QUESTIONS its not question_id ... Its actually id ... but even if i change the question_id right after the WHERE statement to just id .. it still returns nothing

Link to comment
Share on other sites

You're never setting $row, right after this line:

 

$result = $database->query($q);

You should have:

$row = mysql_fetch_assoc($result);

 

edit: That's my fault for not including it in my original code. :s

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.