0

i am having trouble with what seems quite a simple select query, i know there are lots of tutorials out there for this, but none seem to work for me, i keep getting the

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given

Error

Here is the query causing it, basically i just want to select from 2 different tables

$trash_statement = "SELECT * FROM user_inbox, user_outbox WHERE user_inbox.receiver_user_id='$user_id' AND user_outbox.sender_user_id='$user_id' AND mail_deleted='1'";

Any ideas, where i am going wrong?

Thanks

Al Hennessey
  • 2,395
  • 8
  • 39
  • 63
  • What do you see if you run the MySQL directly in MySQL? – Jay Gattuso May 19 '12 at 02:22
  • 2
    Check to see if this is a duplicate of your issue: http://stackoverflow.com/questions/2973202/php-error-mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given – Jim Thomas May 19 '12 at 02:22
  • Hi, i am checking in mysql now, and @Jim Thomas the query works fine as just a single table, but as soon as i add a second then thats where it goes wrong – Al Hennessey May 19 '12 at 02:25
  • When i run it in mysql i get the error - #1052 - Column 'mail_deleted' in where clause is ambiguous - not sure what that means – Al Hennessey May 19 '12 at 02:26
  • mail_deleted is not referred to any table! You need to tell MYSQL with that does that field belong to! – Zuul May 19 '12 at 02:28

1 Answers1

1

mail_deleted is not associated with any table name! That causes Mysql to return an error and not a resource as expected by mysql_fetch_assoc().

MySql Error: saying that the field name is not related to anything

#1052 - Column 'mail_deleted' in where clause is ambiguous

YOUR QUERY

$trash_statement = "
  SELECT * 
  FROM user_inbox, user_outbox 
  WHERE user_inbox.receiver_user_id='$user_id' 
  AND user_outbox.sender_user_id='$user_id' 
  AND yourTableName.mail_deleted='1'";

FIX THIS:

... yourTableName.mail_deleted...

Zuul
  • 16,217
  • 6
  • 61
  • 88
  • Hi, thanks for that, i just did this `SELECT * FROM user_inbox, user_outbox WHERE user_inbox.receiver_user_id = '4' AND user_outbox.sender_user_id = '4' AND user_outbox.mail_deleted ='1' AND user_inbox.mail_deleted ='1'` It works, but it only displays the results from the user_outbox table, and it should display at least 1 results from the user_inbox as well, any ideas? Thanks – Al Hennessey May 19 '12 at 02:35
  • That's another problem! Can only help you by seeing the table structure and it's contents (partially at least)! Post another question related to that issue with the relevant information! (I'll be watching) **Ps:** If it worked, please close this question by accepting the answer! – Zuul May 19 '12 at 02:38