如何在变量中存储以下语句的s.Username
和r.Username
?
$stmt = $this->db->prepare('SELECT
s.Username AS Username1,
r.Username AS Username2,
c.time,
c.message
FROM chatlog c
JOIN user s ON (c.source = s.ID)
JOIN user r ON (c.receiver = r.ID)
WHERE s.ID = :source AND r.ID = :receiver
');
$stmt->execute(array(':source' => $sender, ':receiver' => $buddyID ));
// I want to store the Source and the Username here..
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$chatID = $row['Username1'].$row['r.Username2'];
// ..to create a unique logfile here ..
$dummy = fopen($chatID.".html",'w');
fclose($dummy);
// .. and store the log finally in that file which is used to print in the chatbox
while($log = $stmt->fetch(PDO::FETCH_ASSOC))
{
$fp = fopen($chatID.".html", "a");
fwrite($fp, "<div class='chat_msg'>(" . $log['time'] . ")" . $log['name'] .": " . $log['message'] . "<br />");
fclose($fp);
}
答案 0 :(得分:0)
SELECT
s.Username AS Username1,
r.Username AS Username2,
c.time,
c.message
FROM chatlog c
JOIN user s ON (c.source = s.ID)
JOIN user r ON (c.receiver = r.ID)
WHERE s.ID = :source AND r.ID = :receiver