PHP Table Insert Tr After Every Third Loop

PHP Table Insert Tr After Every Third Loop

Today, We want to share with you PHP Table Insert Tr After Every Third Loop.
In this post we will show you PHP Table Insert Tr After Every Third Loop, hear for PHP Table Insert Tr After Every Third Loop we will give you demo and example for implement.
In this post, we will learn about PHP Table Insert Tr After Every Third Loop with an example.

Simple used to Arithmetic Operators using PHP for PHP Table Insert Tr After Every Third Loop my in this post.

Arithmetic Operators – Modulo

$a % $b
Name : Modulo Description :

Also Read :  CodeIgniter Stripe Payment Gateway Api Integration

Remainder of $a divided by $b.

Simple one or more example of iterate a html table of two row and 3 column using one php query in this post.

Simple Modulus Operators checks whats the leftover of a division.

  • If $i php varible store is 10 , 10/2 = 5 with no leftover , so $i modulus 2 would be 0.
  • If $i php varible store is 10 , 10/3 = 3 with a leftover of 1 , so $i modulus 3 would be 1.

Simple Example of PHP modulo – Arithmetic Operators

<?php
echo "Example 1".(5 % 3)."\n";   // ng4free- output : prints 2
echo "Example 2".(5 % -3)."\n";  // ng4free- output : prints 2
echo "Example 3".(-5 % 3)."\n";  // ng4free- output : prints -2
echo "Example 4".(-5 % -3)."\n"; // ng4free- output : prints -2
?>

Also Read :  How to Insert Data in Database using PHP OOPS

<table>
<?php
$rcount = 0;
while ( $row = mysql_fetch_array($result) ){
    if ($rcount % 3 == 0){
        echo '<tr>';
    }
    echo '<td>'.$row['column_name'].'</td>';
    if ($rcount % 3 == 2){
        echo '</tr>';
    }
    $rcount++; 
}
//here is a check  condition in case you don't have more times multiple of 3 rows
if ($rcount % 3 != 0){
    echo '</tr>';
}

?>
</table>

PHP: End and start a new add

after 6 rows-Example

<tr> 
<?php
$c = 0; // here init Our counter
$n = 6; // Each last Nth iteration would be a new add table row
//using while loop
while ($row = mysql_fetch_array($query))
{
  if($c % $n == 0 && $c != 0) // If the php varible $c is divisible by $n so result...
  {
    // create table row new
    echo '</tr><tr>';
  }
  $c++;
  ?>
  <td><?php echo $row['rangeid']; ?></td>
  <?php
} ?>
</tr>

View Demo

Also Read :  Send WhatsAPP Message API using PHP Step By Step

We hope you get an idea about PHP Table Insert Tr After Every Third Loop
We would like to have feedback on my Information blog .
Your valuable any feedback, Good question, Inspirational Quotes, or Motivational comments about this article are always welcome.
If you liked this post, Please don’t forget to share this as Well as Like FaceBook Page.

We hope This Post can help you…….Good Luck!.

Leave a Reply

Your email address will not be published. Required fields are marked *