0

Trying to retrieve all the data onto one page... I've got this working fine when it's retrieving from one table like so:

$data = mysql_query("SELECT * FROM moduleDetails") 

I've tried doing

("SELECT * FROM moduleDetails, qResponses")

but that doesn't work and is the only thing I can see working.

I've heard about using identifiers? But I'm not quite sure how to use those...

I am new to PHP, any tips/examples would be great.

2
  • You need to specify how to join those two tables. What column links them together? Commented Jan 10, 2014 at 18:22
  • I've got a userno, like a unique number for each participant of the questionniare - how would i use that? Commented Jan 10, 2014 at 18:22

1 Answer 1

2
SELECT md.*, qr.*
FROM moduleDetails md
LEFT JOIN qResponses qr
ON qr.joinColumn = md.joinColumn

Whatever column you used to link them together, use as the joinColumn.

Sign up to request clarification or add additional context in comments.

5 Comments

YES you can't just select all from 2 tables without joining them.
so like this? $data = mysql_query( SELECT md.*, qr.* FROM moduleDetails md LEFT JOIN qResponses qr ON qr.userno = md.userno)
PHP interpret everything that is not in quotes as being constants or functions. The query should be set as a variable. To do so, you should contain it inside quotes
$data = mysql_query('SELECT md.*, qr.* FROM moduleDetails md LEFT JOIN qResponses qr ON qr.userno = md.userno'); DON'T EVER FORGET THE SEMICOLON WHEN YOU END A LINE
IFF the tables are not actually linked in any way, you could use a UNION statement, which simply selects rows from first table, and then the next. w3schools.com/sql/sql_union.asp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.