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 :

Read Also:  How to Insert Data Into MySQL Database Table Using PHP?

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
?>

<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

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

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!.

Read Also:  nested select sql

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Curl GET And POST Method Calls – PHP Example
  2. Read Also:  Vue.js Alert popup-Dialog Box using PHP and CSS
  3. Read Also:  Clear All Cache From Laravel project 5.7
  4. Read Also:  How to use sweet alert for delete confirm in Codeigniter?
  5. Read Also:  how to save data from html form to a database using php?
  6. Read Also:  PHP download file from url using curl example
  7. Read Also:  PHP MySQL Dynamic SQL Insert Query
  8. Read Also:  PHP Secure Token Generator Authentication tutorial
  9. Read Also:  PHP Add Days Hours Minutes and Seconds to Datetime
  10. Read Also:  ng-minlength using Angular Example