<div class="professor_comments">
<?php
#Show User Who Submitted Content
if ($sth2->rowCount()) {
while($row = $sth2->fetch(PDO::FETCH_ASSOC)) {
$theCommentID = $row['CommID'];
}
}
else {
echo "No CommID";
}
echo "Value of CommID: $theCommentID";
echo "<h2 style='margin:0; padding:0;'>Recent Comments</h2>";
if ($sth22->rowCount()) {
while($row = $sth22->fetch(PDO::FETCH_ASSOC)) {
echo "<div class='comment'>by <em>{$row['uname']}</em>";
}
}
else {
echo "User";
}
unset($sth22);
#Show Recent Comments
if ($sth2->rowCount()) {
while($row = $sth2->fetch(PDO::FETCH_ASSOC)) {
echo "on {$row['date']} about <code><a href='course.php?cID={$row['cID']}'>{$row['prefix']} {$row['code']}</a> </code> during {$row['Qtr']}, {$row['Yr']} <span style='float:right; padding-right:5px;'><img src='img/report.png' />
<a class='report' href='report.php?commID={$row['CommID']}'>Report</a></span><br />{$row['info']} </div>";
}
}
else {
echo "<h2 style='color:red;'> No Comments Found, please add some below</div>";
}
unset($sth2);
?>
<?php
// Get any professor comments currently present ON LOAD
$pID2 = filter_input(INPUT_GET, 'pID', FILTER_SANITIZE_NUMBER_INT);
$pdo2 = new PDO('mysql:host=host;dbname=dbname', $u, $p);
$pdo2->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth2 = $pdo2->prepare('
SELECT C.cID, Co.CommID, prefix, code, info, date, Qtr, Yr
FROM Course C, Comment Co, Professor P
WHERE P.pID = ?
AND C.cID = Co.CName AND P.pID = Co.pID
ORDER BY Yr DESC;
');
$sth2->execute(array(
$pID2
));
?>
PHP背后
<?php
// Get the user of the comment
$pID22 = filter_input(INPUT_GET, 'pID', FILTER_SANITIZE_NUMBER_INT);
$pdo22 = new PDO('mysql:host=host;dbname=dbname', $u, $p);
$pdo22->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth22 = $pdo22->prepare("
SELECT uname FROM Student S, Comment C WHERE S.usrID = C.usrID and commID='$theCommentID';
");
$sth22->execute(array(
$pID22
));
?>
This gives me the inital value of the commID outputted, but then seems to ignore all fetching for rows when :
#Show Recent Comments
if ($sth2->rowCount()) {
while($row = $sth2->fetch(PDO::FETCH_ASSOC)) {
is called again. Why is it only outputted the first `commID` but then omitting this second call for `$sth2` :
#Show Recent Comments
if ($sth2->rowCount()) {
while($row = $sth2->fetch(PDO::FETCH_ASSOC)) {
echo "on {$row['date']} about <code><a href='course.php?cID={$row['cID']}'>{$row['prefix']} {$row['code']}</a> </code> during {$row['Qtr']}, {$row['Yr']} <span style='float:right; padding-right:5px;'><img src='img/report.png' />
<a class='report' href='report.php?commID={$row['CommID']}'>Report</a></span><br />{$row['info']} </div>";
}
}
else {
echo "<h2 style='color:red;'> No Comments Found, please add some below</div>";
}
unset($sth2);
问题脚本:我在寻找使用方法:
if ($sth2->rowCount()) {
while($row = $sth2->fetch(PDO::FETCH_ASSOC)) {
两次在我上面的代码和它不让我,我不会在解封的中间代码..
什么是你的问题? – pkk
^请更新请求 – user886187
您可以将它缩小到测试用例,而不是用所有这些PHP ..和HTML轰炸我们! –