The code may not make much sense . This is just me just getting to know to code :) I am making a chat where i am getting the chat messages from a mysql database and i want to output the data from the database in separate div`s using another function. I have som dificulties getting this to work!
Function to get the data from the database
function messages($user_id) {
$user_id = (int)$user_id;
$data = mysql_fetch_assoc(mysql_query("SELECT chat_content.chat_content_id, user.user_id, user.username, chat_content.chat_content, group_info.group_name FROM user, chat_content, group_info WHERE user.user_id = chat_content.user_id AND group_info.group_info_id = chat_content.group_info_id AND user.user_id = '$user_id'"));
return $data;
}
Function to output the data from the other function to a page
function messages_structure($user_id) {
messages($user_id);
$chat_id = $data[0]['chat_content_id'];
$output = array();
foreach($chat_id) {
$output[] = '<div id="chat_main_textbox"' . $chat_id . '</div>';
}
return '<div id="wrap">' .implode('', $output). '</div>';
}
Page output
$user_id = 56;
echo messages_structure($user_id);