Reputation: 89
I have the following MySQL query and I want to echo a specific row when a condition is satisfied;
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);
I want to echo row 3 when the Author equals $post_author, can someone help me with this. Thanks.
<?php echo "{$row[3]}";?> where Author=$post_author
Upvotes: 0
Views: 589
Reputation: 3123
I believe a simple if
would make you happy:
if ($row[0] == $post_author)
echo $row[3];
Upvotes: 1