Home > Backend Development > PHP Tutorial > pdo mysql怎么输出第1条 第4条 第7条数据

pdo mysql怎么输出第1条 第4条 第7条数据

WBOY
Release: 2016-06-23 14:05:11
Original
881 people have browsed it

pdo mysql怎么输出第1条  第4条 第7条数据。。

下面是输出全部数据。。

<?php  $pdo = new PDO("mysql:host=localhost;dbname=uzhan","root","");  $sql1="select * from www"; $rs = $pdo -> query($sql1);  while($row = $rs -> fetch()) {  echo'<div>'.$row[id].'</div>'; } ?>
Copy after login


回复讨论(解决方案)

<?php  $pdo = new PDO("mysql:host=localhost;dbname=uzhan","root","");  $sql1="select * from www"; $rs = $pdo -> query($sql1); $num = 0; while($row = $rs -> fetch())  { $num++;if(1==$num || 4==$num || 7==$num)   echo'<div>'.$row[id].'</div>';  }
Copy after login

?>



<?php$pdo = new PDO("mysql:host=localhost;dbname=uzhan","root","");$sql1="select * from www";$rs = $pdo -> query($sql1);$flag = 1;while($row = $rs -> fetch()){  if(($flag-1)%3 == 0){    echo'<div>'.$row[id].'</div>';  }  $flag++;}
Copy after login


未经测试,应该没问题。

  $pdo = new PDO("mysql:host=localhost;dbname=uzhan","root","");  $sql1="select * from www"; $rs = $pdo -> query($sql1);  while($row = $rs -> fetch()){ $i = 1;if($i % 3 ==1){ echo'<div>'.$row[id].'</div>';  }  $i = $i + 1;}
Copy after login

那显示 2  5   8  11     呢。。
显示3  6  9 。。。。呢 我算法不太好了 

打错了  是显示 1  5   9   13  。。
             2  6  10   15。。
             3  7  11  16。。
             4 8  12  17。。。

这个4条。。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template