pdo mysql按DESC选择顺序无效

时间:2015-10-02 19:30:19

标签: php mysql pdo

使用pdo命令显示表中的数据desc不工作,但是当我使用mysql时它可以工作。问题是什么? 这是我得到的输出。

enter image description here

我想要的输出是:

enter image description here

SELECT * from articles ORDER BY article_id DESC //works.in PHPMYADMIN

然而,这不起作用:

 $query = $pdo->prepare("SELECT * from articles ORDER BY article_id DESC " );

$query->execute();

$ num = $ query-> rowcount();

如果($ num!== 0){//这不起作用,它会显示结果而不是降序,问题出在哪里?

 //code that display data 
echo ' <div id="form"> <p   class="regp" align="center" >list of articles.</p>';
echo' <table class="tab"   border=1 BORDERCOLOR=#00FF00>
  <tr>

   <th>   <input type="button" style="border:2px solid black"id="toggle" class="buttons" value="action" onClick="do_this()" /></th>
    <th>articles</th>

     <th>categorie</th>
     <th>date</th>

  </tr>';
  foreach  ($articles as $article){ 
     echo'<tr>'; 
    echo'<td><input type="radio" name="id[]" id="checkALL" value='. $article['article_id'].'>edit</input></td>';
    ?>
<td>  <?Php echo $article['article_title'];?>. <a  style="text-decoration: underline;"  href="article.php?id=<?php echo $article['article_id'];?>"><font color="grey">view</font></a></td>
  <?php
       echo'<td>'. $article['categorie'].'</td>';
       echo'<td>'. $article['article_date'].'</td>';  

  }

  echo '</table>';
    echo '              <pre>                                     <input class="fatigué" type="submit" name="edit"  value="edit article"></input></pre></div>';

 }
       else {
    echo '<p class="tab"> sorry you have 0 articles .</p>';
    }

0 个答案:

没有答案
相关问题