Creating a Variable From Two Others
Posted
by John
on Stack Overflow
See other posts from Stack Overflow
or by John
Published on 2010-05-31T15:41:52Z
Indexed on
2010/05/31
15:42 UTC
Read the original article
Hit count: 167
php
Hello,
In the HTML table below, I would like to add a third column that equals $row["countSubmissions"] times 10 plus $row["countComments"]. How could I do this?
Thanks in advance,
John
$sqlStr = "SELECT
l.loginid,
l.username,
COALESCE(s.total, 0) AS countSubmissions,
COALESCE(c.total, 0) AS countComments
FROM login l
LEFT JOIN (
SELECT loginid, COUNT(1) AS total
FROM submission
GROUP BY loginid
) s ON l.loginid = s.loginid
LEFT JOIN (
SELECT loginid, COUNT(1) AS total
FROM comment
GROUP BY loginid
) c ON l.loginid = c.loginid
GROUP BY l.loginid
ORDER BY countSubmissions DESC
LIMIT 10";
$result = mysql_query($sqlStr);
$arr = array();
echo "<table class=\"samplesrec1edit\">";
while ($row = mysql_fetch_array($result)) {
echo '<tr>';
echo '<td class="sitename1edit1"><a href="http://www...com/.../members/index.php?profile='.$row["username"].'">'.stripslashes($row["username"]).'</a></td>';
echo '<td class="sitename1edit2">'.stripslashes($row["countSubmissions"]).'</td>';
echo '<td class="sitename1edit2">'.stripslashes($row["countComments"]).'</td>';
echo '</tr>';
}
echo "</table>";
© Stack Overflow or respective owner