The whole code works, but the problem appears when I'm trying to get data from the database:
For fetching data, I'm using PHP:
function chatStory() {
$sql = mysql_query("SELECT * FROM chat WHERE username = '".$_SESSION['username']."' ");
$rows = array();
while($r = mysql_fetch_assoc($sql)) {
$rows[] = $r;
}
echo json_encode($rows);
}
Then I'm able to retrieve that data by JavaScript:
$.ajax({
url: 'chat.php?action=chatstory', data: "", dataType: 'json', success: function(rows)
{
for (var i in rows)
{
var row = rows[i];
var msg = row[0];
var user = row[1];
$("#chat_"+nazwa+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagefrom">'+user+': </span><span class="chatboxmessagecontent">'+msg+'</span></div>');
}
}
});
I can't find my error. Every message is showing. There are 7 messages in the database and I can see 7 messages in the chatbox, but they are appearing as undefined.