psychohagis Posted January 6, 2007 Share Posted January 6, 2007 I currently have two tables for my site[b]Users (this is a simplified version):[/b][img]http://www.buckschildminding.org.uk/userssimple.PNG[/img][b]and messages:[/b][img]http://www.buckschildminding.org.uk/messages.PNG[/img]Now I have a page which I want to display all the messages for the person who's currently signed in, and use "from1" (which is the user id of the person the message is from) to get the senders username.I currently have the following SQL statement:[code]$messages = @mysql_query( 'SELECT id, from1, subject, message, received, read1, username FROM messages, users WHERE to="' . $userid . '" AND from1="users.id"');[/code]but this does not work and returns the follwing error:[quote]Error performing query: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'to="1" AND from1="users.id"' at line 2[/quote]can anyone help? Quote Link to comment Share on other sites More sharing options...
psychohagis Posted January 6, 2007 Author Share Posted January 6, 2007 *bump* Quote Link to comment Share on other sites More sharing options...
psychohagis Posted January 6, 2007 Author Share Posted January 6, 2007 *bump* Quote Link to comment Share on other sites More sharing options...
Hypnos Posted January 6, 2007 Share Posted January 6, 2007 This is a MySQL question. You should of asked in that forum.It painful to watch people try to build querys in PHP. You should test your querys directly first (Like in the mysql client or PHPMyAdmin) when you're building them. I think what you want is more like this:SELECT id.messages, from1.messages, subject.messages, message.messages, received.messages, read1.messages, username.UsersFROM messages LEFT JOIN UsersON id.messages=id.UsersWHERE to.messages="1"But I'm not an expert at SQL, and I don't know what your table contents look like. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.