Jump to content

[SOLVED] linking tables


psychohagis

Recommended Posts

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?
Link to comment
Share on other sites

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.Users
FROM messages
LEFT JOIN Users
ON id.messages=id.Users
WHERE to.messages="1"


But I'm not an expert at SQL, and I don't know what your table contents look like.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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