下面的查询不返回任何结果。我已经从正在运行的查询中复制了它,唯一不同的是添加了以下条件:


  WHERE Submittingid = $ Submissionid


有什么想法为什么这个查询不返回任何结果?

$sqlStr2 = "SELECT
                s.loginid
                ,s.title
                ,s.url
                ,s.displayurl
                ,s.datesubmitted
                ,l.username
                ,s.submissionid
                ,COUNT(c.commentid) countComments
             FROM submission s
            INNER JOIN login l ON s.loginid = l.loginid
       LEFT OUTER JOIN comment c ON s.submissionid = c.submissionid
              GROUP BY s.submissionid
             WHERE submissionid=$submissionid
             ORDER BY s.datesubmitted DESC
             LIMIT 10";

$tzFrom2 = new DateTimeZone('America/New_York');
$tzTo2 = new DateTimeZone('America/Phoenix');

$result2 = mysql_query($sqlStr2);

$arr2 = array();
echo "<table class=\"samplesrec\">";
while ($row2 = mysql_fetch_array($result2)) {
    $dt2 = new DateTime($row2["datesubmitted"], $tzFrom2);
    $dt2->setTimezone($tzTo2);
    echo '<tr>';
    echo '<td class="sitename1"><a href="http://www.'.$row2["url"].'" TARGET="_blank">'.$row2["title"].'</a>  <div class="dispurl">'.$row2["displayurl"].'</div></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="sitename2name">Submitted by <a href="http://www...com/.../members/index.php?profile='.$row2["username"].'">'.$row2["username"].'</a> on '.$dt2->format('F j, Y &\nb\sp &\nb\sp g:i a').'</td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="sitename2"><a href="http://www...com/.../comments/index.php?submissionid='.$row2["submissionid"].'">'.$row2["countComments"].' comments</a></td>';
    echo '</tr>';
    }
echo "</table>";

最佳答案

c.submissionids.submissionid-也许您应该在查询中说明要使用的那个。示例:WHERE s.submissionid=$submissionid
我认为GROUP BY应该放在WHERE子句之后。

09-10 02:46
查看更多