Jump to content

Show every 3rd entry from table


thaidomizil

Recommended Posts

Hello,

 

i'm trying to query mysql to show table contents, my code so far is this:

 

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM codes";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

 

to show content:

 

<?php
$i=0;
while ($i < $num) {

$f1=mysql_result($result,$i,"id");
$f2=mysql_result($result,$i,"code");
$f3=mysql_result($result,$i,"secret");
$f4=mysql_result($result,$i,"date");
$f5=mysql_result($result,$i,"ip");

?>

<tr>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td>

</tr>

Now this shows all the content from the table, what i want to have is 2 scripts which should work like this:

 

Script1 to show table contents:

ID1, ID2, ID4, ID5, ID7, ID8 and so on.

 

Script2 to show table contents:

ID3, ID6, ID9 and so on.

 

Basically one that shows only every 3rd and skips 1 and 2, and another one that skips every 3rd.

Is this possible ?

 

Thanks !

Link to comment
https://forums.phpfreaks.com/topic/248711-show-every-3rd-entry-from-table/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.