Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP, MySQL: How to get the user's first and last name
    primarykey
    data
    text
    <p>I got stucked with this query in the past couple of hours, and I badly need someone to help me figure it out. I'm try to finish my private message system, but I lost myself in the database tables. I've created three tables for the system, and they are as follows:</p> <pre><code>CONVERSATION(**conversation_id**, subject) CONVERSATION_MEMBER(**conversation_id**, **user_id**, conversation_last_view, conversation_deleted) CONVERSATION_MESSAGE(**message_id**, conversation_id, user_id, message_date, message_text) </code></pre> <p>Ok, so in my function to get all conversations of a specific user, I'm fetching the subject, the date, and at last I want to show the user who is he/she talking to. I wrote the following query:</p> <pre><code>SELECT c.conversation_id, c.conversation_subject, MAX(cmes.message_date) AS conversation_last_reply, FROM conversation c, conversation_member cmem, conversation_message cmes WHERE c.conversation_id = cmes.conversation_id AND c.conversation_id = cmem.conversation_id AND cmem.user_id = {$_SESSION['user_id']} AND cmem.conversation_deleted = 0 GROUP BY c.conversation_id ORDER BY conversation_last_reply DESC </code></pre> <p>And, at last I'm tryin to get the user's first and last name (the other user in the conversation), but I lost myself on how to do that. I've tried to create another function that will get the conversation id, while looping through the results of the first query, and return the user's first and last name, but it didn't work out.</p> <p>Btw, for the users I have another table... I guess I don't have to tell you. Ok, thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload