0

PHP/PDO などについてさらに知識を得るために、小さなプライベート フォーラムを作成しています。これは私のコードです。

$sql2 = $db->prepare('SELECT topic_id, topic_subject,topic_date,topic_cat FROM topics WHERE topic_cat = :topid');
$sql2->bindParam(':topid', $_GET['id'], PDO::PARAM_INT);    
$sql2->execute();
$result2 = $sql->rowCount();    
if($result2 === FALSE){
    echo 'The topics could not be displayed, please try again later.';
}
elseif ($result2 === 0){
    echo 'There are no topics in this category yet.';
} else {
    //prepare the table
    echo '<table border="1">
      <tr>
          <th>Topic</th>
          <th>Created at</th>
      </tr>';   

    while($row = $sql2->fetch()) {              
        echo '<tr>';
        echo '<td class="leftpart">';
        echo '<h3><a href="topic.php?id=' . $row['topic_id'] . '">' . $row['topic_subject'] . '</a><br /><h3>';
        echo '</td>';
        echo '<td class="rightpart">';
        echo date('d-m-Y', strtotime($row['topic_date']));
        echo '</td>';
        echo '</tr>';
    }
}

echoatが表示されるはずですwhile($row = $sql2->fetch())が、そうではありません。{また、十分ではないことはわかってい}ますが、それはコードの他の部分が関連していないためです。

4

1 に答える 1