回声mysql查询行

时间:2013-06-24 12:11:13

标签: php mysql

我有以下MySQL查询,并且我想在条件满足时回显特定行;

global $post;
$post_author = $post->post_author;
$result = mysql_query("SELECT *, @rownum := @rownum + 1 from
    (
    SELECT (display_name) 'Author',
        IFNULL(ROUND(SUM(balance.meta_value),2),2) 'Balance'
    FROM posts p
    JOIN users u 
        ON p.post_author = u.ID
    JOIN postmeta odd ON p.ID = odd.post_id AND odd.meta_key = 'odd' AND odd.meta_value >= 1.5
    LEFT JOIN postmeta balance 
        ON p.ID = balance.post_id AND balance.meta_key = 'balance'
    WHERE p.post_status = 'publish'
    GROUP BY u.ID
    ORDER BY Balanco DESC
    )x, (SELECT @rownum := 0) r");
$row = mysql_fetch_array($result);

我想在作者等于$ post_author时回显第3行,有人可以帮我解决这个问题。感谢。

<?php echo "{$row[3]}";?> where Author=$post_author

1 个答案:

答案 0 :(得分:1)

我相信一个简单的if会让你开心:

if ($row[0] == $post_author)
    echo $row[3];