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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.