View Single Post
Old 12-02-2012, 05:08 AM   PM User | #10
KULP
Regular Coder

 
Join Date: Mar 2012
Posts: 166
Thanks: 5
Thanked 11 Times in 11 Posts
KULP is an unknown quantity at this point
Can you explain how JOINs work?

I think I understand the syntax of this, but how does this store in $sQry? Is this a 2D array? In other words, how do I access each value? Sorry, this is probably a stupid question. Also, did you memorize how to write this off the top of your head?

PHP Code:
$sQry 'SELECT q.questionID, q.questionDescription, qo.optionID, qo.option
            FROM question q
            INNER JOIN questionoption qo ON qo.questionID = q.questionID
            ORDER BY q.questionID ASC'

EDIT: I tried this in my own project and I get the error:
Code:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Simpolls\user.php on line 37
I have tables: users, polls, and choices. Polls contains userid, and choices contains pollid. I'm trying to get all polls with userid $currentid and then join those results with the choices for each poll (pollid). 'date' is a timestamp value in my polls table, if that sounds right. Hmm...
PHP Code:
$result mysql_query('SELECT *
                FROM polls p WHERE p.userid = "' 
$currentid '" 
                INNER JOIN choices c ON c.pollid = p.pollid
                ORDER BY p.date DESC'
$connection);
                
                while(
$row mysql_fetch_array($result))
                {
                    echo 
$row['question'];
                } 

Last edited by KULP; 12-02-2012 at 09:03 AM..
KULP is offline   Reply With Quote