老实说,我不知道我的代码有什么问题,有人可以试着解释一下吗? 我似乎无法返回$ messages数组,原因有些奇怪,即使我之前使用了相同的方法..
<?php
$messages = get_msg();
foreach($messages as $message){
echo '<strong>'.$message['sender'].' Sent</strong><br/>';
echo $message['message']. '<br/><br/>';
}
?>
function get_msg(){
global $db_host, $db_user, $db_pass, $db_name;
$query = ("SELECT (sender, message) FROM chat LIMIT 10 OFFSET 15");
$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if($result = $conn->query($query)){
$messages = array();
$count=0;
while($row = $result->fetch_assoc()){
$messages[$count] = array('sender'=>$row['sender'],
'message'=>$row['message']);
$count++;
}
return $messages;
}
}