Table not Echoing out if another Table has a Zero value
Posted
by John
on Stack Overflow
See other posts from Stack Overflow
or by John
Published on 2010-05-12T20:10:12Z
Indexed on
2010/05/12
20:14 UTC
Read the original article
Hit count: 268
Hello,
The table below with mysql_query($sqlStr3)
(the one with the word "Joined" in its row) does not echo if the result associated with mysql_query($sqlStr1)
has a value of zero. This happens even if mysql_query($sqlStr3)
returns a result.
In other words, if a given loginid has an entry in the table "login", but not one in the table "submission", then the table associated with mysql_query($sqlStr3)
does not echo.
I don't understand why the "submission" table would have any effect on mysql_query($sqlStr3)
, since the $sqlStr3 only deals with another table, called "login", as seen below.
Any ideas why this is happening?
Thanks in advance,
John W.
<?php
echo '<div class="profilename">User Profile for </div>';
echo '<div class="profilename2">'.$profile.'</div>';
$tzFrom = new DateTimeZone('America/New_York');
$tzTo = new DateTimeZone('America/Phoenix');
$profile = mysql_real_escape_string($_GET['profile']);
$sqlStr = "SELECT l.username, l.loginid, s.loginid, s.submissionid, s.title, s.url, s.datesubmitted, s.displayurl
FROM submission AS s
INNER JOIN login AS l
ON s.loginid = l.loginid
WHERE l.username = '$profile'
ORDER BY s.datesubmitted DESC";
$result = mysql_query($sqlStr);
$arr = array();
echo "<table class=\"samplesrec1\">";
while ($row = mysql_fetch_array($result)) {
$dt = new DateTime($row["datesubmitted"], $tzFrom);
$dt->setTimezone($tzTo);
echo '<tr>';
echo '<td class="sitename3">'.$dt->format('F j, Y &\nb\sp &\nb\sp g:i a').'</a></td>';
echo '<td class="sitename1"><a href="http://www.'.$row["url"].'">'.$row["title"].'</a></td>';
echo '</tr>';
}
echo "</table>";
$sqlStr1 = "SELECT l.username, l.loginid, s.loginid, s.submissionid, s.title, s.url, s.datesubmitted, s.displayurl, l.created, count(s.submissionid) countSubmissions
FROM submission AS s
INNER JOIN login AS l
ON s.loginid = l.loginid
WHERE l.username = '$profile'";
$result1 = mysql_query($sqlStr1);
$arr1 = array();
echo "<table class=\"samplesrec2\">";
while ($row1 = mysql_fetch_array($result1)) {
echo '<tr>';
echo '<td class="sitename5">Submissions: '.$row1["countSubmissions"].'</td>';
echo '</tr>';
}
echo "</table>";
$sqlStr2 = "SELECT l.username, l.loginid, c.loginid, c.commentid, c.submissionid, c.comment, c.datecommented, l.created, count(c.commentid) countComments
FROM comment AS c
INNER JOIN login AS l
ON c.loginid = l.loginid
WHERE l.username = '$profile'";
$result2 = mysql_query($sqlStr2);
$arr2 = array();
echo "<table class=\"samplesrec3\">";
while ($row2 = mysql_fetch_array($result2)) {
echo '<tr>';
echo '<td class="sitename5">Comments: '.$row2["countComments"].'</td>';
echo '</tr>';
}
echo "</table>";
$tzFrom3 = new DateTimeZone('America/New_York');
$tzTo3 = new DateTimeZone('America/Phoenix');
$sqlStr3 = "SELECT created, username
FROM login
WHERE username = '$profile'";
$result3 = mysql_query($sqlStr3);
$arr3 = array();
echo "<table class=\"samplesrec4\">";
while ($row3 = mysql_fetch_array($result3)) {
$dt3 = new DateTime($row3["created"], $tzFrom3);
$dt3->setTimezone($tzTo3);
echo '<tr>';
echo '<td class="sitename5">Joined: '.$dt->format('F j, Y').'</td>';
echo '</tr>';
}
echo "</table>";
?>
</body>
</html>
© Stack Overflow or respective owner