1
次の文の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);
}