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 [email protected]

 

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
https://forums.phpfreaks.com/topic/181954-solved-query-help/
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 = '[email protected]') ORDER BY RAND() LIMIT 1";
$result = mysql_query($sql);
echo $row['question'];

Link to comment
https://forums.phpfreaks.com/topic/181954-solved-query-help/#findComment-959759
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
https://forums.phpfreaks.com/topic/181954-solved-query-help/#findComment-959770
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.