0

我正在做一个私人消息系统。我的表单正确地发布到我的表中,但返回查询拉出了一些奇怪的东西。我对加入表格有点陌生......

带有 sql 查询的 PHP 代码:

function fetch_messages()  {
    $sql = "SELECT
                `conversations`.`con_id`,
                `conversations`.`con_subject`,
                MAX(`conversations_messages`.`message_date`) AS `con_last_reply`
            FROM `conversations`
            LEFT JOIN `conversations_messages` ON `conversations`.`con_id` = `conversations_messages`.`con_id`
            INNER JOIN `conversations_members` ON `conversations`.`con_id` = `conversations_members`.`con_id`
            WHERE `conversations_members`.`user_id` = 31
            AND `conversations_members`.`con_deleted` = 0
            GROUP BY `conversations`.`con_id`
            ORDER BY `con_last_reply` DESC";

    $result = mysql_query($sql);

    $conversations = array();

    while (($row = mysql_fetch_assoc($result))  !== false)  {

        $conversations[] = array(
        `id`        => $row['con_id'],
        `subject` => $row['con_subject'],
        `con_last_reply` => $row['last_reply']
        );
    }
    return $conversations;
}

返回数组:

Array ( [0] => Array ( 
                [uid=8927072(user007) gid=100450(inetuser) groups=100450(inetuser) ] => 1
                [] => ) )

(这几乎就像它在返回我的 ftp 信息?user007 是我打开的 ftp 连接名称,但这不是表格中的内容!!)

4

1 回答 1

2

您使用了错误类型的引号。它应该是:

    $conversations[] = array(
    'id'        => $row['con_id'],
    'subject' => $row['con_subject'],
    'con_last_reply' => $row['last_reply']
    );

反引号就像在 shell 或 Perl 中一样,它们运行命令并将其输出作为字符串返回。

直到这个问题我才知道 PHP 有这个功能。

文档

于 2013-01-24T01:21:54.827 回答