Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP MySQL函数数组没有输出_Php_Mysql_Sql_Function_Output - Fatal编程技术网

PHP MySQL函数数组没有输出

PHP MySQL函数数组没有输出,php,mysql,sql,function,output,Php,Mysql,Sql,Function,Output,在私有消息系统的后端文件中,在函数fetch_conversation_messages结尾的while语句中声明了一个数组的值。但是,显示的数组是空白的(我用于调试的echos和print_r除外) 我对这个论坛非常陌生,PHP和MySQL,所以请帮助我 先谢谢你 // Fetches all of the messages in the given converstion. function fetch_conversation_messages($conversation_id){

在私有消息系统的后端文件中,在函数fetch_conversation_messages结尾的while语句中声明了一个数组的值。但是,显示的数组是空白的(我用于调试的echos和print_r除外)

我对这个论坛非常陌生,PHP和MySQL,所以请帮助我

先谢谢你

// Fetches all of the messages in the given converstion.
function fetch_conversation_messages($conversation_id){
    $conversation_id = (int)$conversation_id;

    $sql = "SELECT
  `conversations_messages`.`message_date`,
  `conversations_messages`.`message_text`,
  `users`.`user_name`
FROM `conversations_messages`
INNER JOIN `users` ON `conversations_messages`.`user_id` = `users`.`user_id`
WHERE `conversations_messages`.`conversation_id` = {$conversation_id}
ORDER BY `conversations_messages`.`message_date` DESC";

    $result = mysql_query($sql);
    var_dump($result);
    $messages = array();

    while (($row = mysql_fetch_assoc($result)) !== false){
            $messages[] = array(
                    'date'          => $row['message_date'],
                    'unread'        => $row['message_unread'],
                    'text'          => $row['message_text'],
                    'user_name'     => $row['user_name'],
            );
      echo mysql_num_rows($result);
                    var_dump($row);

    }
echo count($messages);}
此外,view_conversation.page.inc.php中存在一个foreach错误(写在下面作为对第一个答案的注释),即此页面:

    <?php

$errors = array();
$valid_conversation = (isset($_GET['conversation_id']) && validate_conversation_id($_GET['conversation_id']));
if ($valid_conversation === false){
        $errors[] = 'Invalid Conversation ID.';
}
if (isset($_POST['message'])){
        if (empty($_POST['message'])){
                $errors[] = 'You must enter a message.';
        }

        if (empty($errors)){
                add_conversation_message($_GET['conversation_id'], $_POST['message']);
        }
}

if (empty($errors) === false){
        foreach ($errors as $error){
        }
}
echo $error;

if ($valid_conversation){
        /*if (isset($_POST['message'])){
                update_conversation_last_view($_GET['conversation_id']);*/
                $messages = fetch_conversation_messages($_GET['conversation_id']);
                print_r($messages);
        /*}else{
                $messages = fetch_conversation_messages($_GET['conversation_id']);
                update_conversation_last_view($_GET['conversation_id']);
        }*/

}
?>
<a href="index.php?page=inbox">Inbox</a>
<a href="index.php?page=logout">Logout</a>

        <form action="" method="post">
                <p><textarea name="message" rows="10" cols="110"></textarea></p>
                <p><input type="submit" value="Add Message" /></p>
        </form>

        <?php
        foreach ($messages as $message){
        ?>
        <?php if ($message['unread']) echo 'unread'; ?>
        <p class="name">Username: <?php echo $message['user_name']; ?></p>
        <p class="text">Date: <?php echo date('d/m/Y H:i:s', $message['date']); ?></p>
        <p>Message: <?php echo $message['text']; ?></p>

<?php

}
?>

用户名:

日期:

信息:


您得到了什么?您希望得到什么?您是否尝试过手动运行查询以确保确实有结果?我的意思是,在phpMyAdmin或similarI中,我已经尝试过了,但是它依赖于太多的变量,所以很难正确测试。我想得到类型为(mysql结果)0的资源(16),我希望得到一个包含“日期”、“未读”、“文本”、“用户名”的数组