为什么这个变量不能获取值?

时间:2011-08-20 03:33:38

标签: php mysql string

<?php                                                                        
                #Show Recent Comments
                $theCommentID = $row['CommID'];
                echo "<h2 style='margin:0; padding:0;'>Recent Comments</h2>";
                if ($sth2->rowCount()) {                                     
                while($row = $sth2->fetch(PDO::FETCH_ASSOC)) {               
                    echo "<div class='comment'>by <em>{$row22['uname']}</em> on {$row['date']} about <code><a href='course.php?cID={$row['cID']}'>{$row['prefix']} {$row['code']}</a>&nbsp;</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);                                                                                                                
?>  

$pdo = new PDO('mysql:host=host;dbname=db', $u, $p);
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sth = $pdo->prepare('
    SELECT name, lname, fname, picpath, email
    FROM Department, Professor
    WHERE pID = ?
    AND Department.dID = Professor.dID;
    ;');
$sth->execute(array(
    $pID
));
?>

<?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=db', $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
// Get the user of the comment
$pID22 = filter_input(INPUT_GET, 'pID', FILTER_SANITIZE_NUMBER_INT);
        $pdo22 = new PDO('mysql:host=host;dbname=db', $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
        ));

?>  

为什么<em>{$row22['uname']}</em>绝对没有价值?

我已经尝试在数据库中测试sth22查询,以确保在尝试此操作之前它给了我所需的内容。

2 个答案:

答案 0 :(得分:2)

似乎$ row22没有为我设置值。据我所知,22号线不应该在第7行。

答案 1 :(得分:0)

应该只读......

<em>{$row['uname']}</em>
22不属于那里。