php - `While` Not showing echo -
i'm having trouble getting echo showing up. think there problem while
table in mysql should work normally. code
<?php $sql = $db->prepare('select topic_id, topic_subject topics topics.topic_id = :topid'); $sql->bindparam(':topid', $_get['id'], pdo::param_int); $sql->execute(); $result = $sql->rowcount(); if($result === false){ echo 'the topic not displayed, please try again later.'; } elseif(count($result) === 0){ echo 'this topic doesn′t exist.'; } else { while($row = $sql->fetch()) { //display post data echo '<table class="topic" border="1"> <tr> <th colspan="2">' . $row['topic_subject'] . '</th> </tr>'; ?>
the while
should show because topic exists in mysql. when i'm using avar_dump($sql->errorinfo());
say's array(3) { [0]=> string(5) "00000" [1]=> null [2]=> null }
null because created topic in mysql test.
$result = $sql->rowcount(); elseif(count($result) === 0){
$result being assigned row count; count()
designed count elements in array. manual
if var not array or object implemented countable interface, 1 returned. there 1 exception, if var null, 0 returned.
i think need is:
elseif($result === 0){
what think's happening there no results query, call count()
isn't working. it's passing check, , since there no records retrieve, it's not going loop.
Comments
Post a Comment