2011-08-20 82 views
-2
<?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查詢,以確保在嘗試此操作之前給了我所需的數據。

+1

有完全沒有提到在你的代碼的任何地方任何一個'$ row22',然後就在你的問題的最後,你隨便提,你試圖使用它「的地方」,但沒有成功。它在哪裏設置?它在哪裏使用? –

回答

2

彷彿$ row22是有史以來值設置爲我它不會出現。從我所知道的,22不應該在那裏第7行

+0

這並不能解決任何問題。 – user886187

+0

這是否代碼:'$ theCommentID = $行[ 'CommID'];'中設置的值的腳本? – user886187

+0

@ user886187這確實* *決心東西。它指出,你正在使用一個變量'$ row22'是**不存在**的代碼,你已經證明。 – ceejayoz

0

它應該只是讀...

<em>{$row['uname']}</em> 

22不屬於那裏。

+0

Tha不起作用。它的調用uname來自$ row之外的其他查詢,它從$ row22調用它..請參閱上面的php代碼。 – user886187

相關問題