如果与mysql_query($sqlStr3)
关联的结果的值为零,则下面的HTML表mysql_query($sqlStr1)
(其行中带有“已加入”一词的那个)不会回显。即使mysql_query($sqlStr3)
返回结果,也会发生这种情况。
换句话说,如果给定的loginid在MySQL表“login”中有一个条目,但在MySQL表“submission”中没有,则与mysql_query($sqlStr3)
相关联的表不会回显。
我不明白为什么MySQL“submission”表会对mysql_query($sqlStr3)
产生任何影响,因为$ sqlStr3只处理另一个名为“login”的MySQL表,如下所示。
为什么会发生这种情况?
提前致谢,
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>
答案 0 :(得分:1)
如果我正确理解了问题,您需要在代码的最后一行中回显$dt3->format('F j, Y')
而不是$dt->format('F j, Y')
。
答案 1 :(得分:1)
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>";
您是否希望在此回音中调用$ dt3-&gt;格式('F j,Y'),而不是$ - &gt;格式('F j,Y')? $ dt3我没有看到任何其他用途。