区分ID

时间:2017-05-17 13:38:21

标签: php html sql sql-server-2008

这是我的疑问:

$tsql = "SELECT *
FROM 
    dbo.messages m INNER JOIN
    dbo.contacts c
    ON m.contactID = c.ID
WHERE 
    assigned='{$_COOKIE['member_name']}'
ORDER BY
    m.status DESC, m.ID DESC";

这将返回联系人ID,但不返回消息ID。如何让它显示:

<?php echo $row['ID'] ?>

但是使用消息ID而不是HTML表单中的联系人ID?

1 个答案:

答案 0 :(得分:2)

你可以使用cid访问c表的id,m table的id作为mid

喜欢$ row [&#39; cid&#39;]和$ row [&#39; mid&#39;]

    $tsql = "SELECT m.*, c.*, c.id as cid, m.id as mid
    FROM 
        dbo.messages m INNER JOIN
        dbo.contacts c
        ON m.contactID = c.ID
    WHERE 
        assigned='{$_COOKIE['member_name']}'
    ORDER BY
        m.status DESC, m.ID DESC";