Table not Echoing out if another Table has a Zero value
The HTML 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 MySQL table "login", but not one in the MySQL table "submission", then the table associated with mysql_query($sqlStr3)
does not echo.
I don't understand why the MySQL "submission" table would have any effect on mysql_query($sqlStr3)
, since the $sqlStr3 only deals with another MySQL 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>
If I understand the problem correctly, you need to echo out $dt3->format('F j, Y')
instead of $dt->format('F j, Y')
in one of the last lines of the code you have.
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>";
Are you looking to call $dt3->format('F j, Y') in the echo here, instead of $->format('F j, Y')? I don't see any other use for $dt3.
精彩评论