Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7986261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:48:23+00:00 2026-06-04T11:48:23+00:00

I am trying to use for loops to create a table which dynamically returns

  • 0

I am trying to use for loops to create a table which dynamically returns something like this: Note how the td content have been arranged

<table>
 <tr>
  <td>1</td>
  <td>3</td>
  <td>5</td>
  <td>7</td>
  <td>9</td>
 </tr>
 <tr>
  <td>2</td>
  <td>4</td>
  <td>6</td>
  <td>8</td>
  <td>10</td>
 </tr>
</table>

among What I have tried so far is

$row=2;
$col=20;
$x=0;
echo '<table>';
for($i=0;$i<$row;$i++){
   echo '<tr>';
     for($k=0;$k<$col;$k++)
     {
        echo '<td>'.echo $x+=1.'</td>';
     }
   echo '</tr>';

}

In this case I get something different and which is not what I want.

<table>
    <tr>
     <td>1</td>
     <td>2</td>
     <td>3</td>
     <td>4</td>
     <td>5</td>
    </tr>
    <tr>
     <td>6</td>
     <td>7</td>
     <td>8</td>
     <td>9</td>
     <td>10</td>
    </tr>
  </table>

Kindly someone help me map this.Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:48:25+00:00Added an answer on June 4, 2026 at 11:48 am
    <?php 
      # how high to count
      $count = 10;
    
      # how many rows in the table
      $rows = 2;
    
      # figure out how many columns
      $columns = ceil($count/$rows);
    
      # could also go the other way and declare there to be 5 columns and then 
      # divide to get the rows, but since you're counting down the columns, 
      # I thought this made more sense.  Either way.
    
    ?><table><?php 
    
      for ($i=0; $i<$rows; ++$i) {
    
     ?><tr><?php
    
        for ($j=0; $j<$columns; ++$j) {
    
          # calculate which number to show in column $j of row $i.  Each column adds
          # $rows numbers to the total, while each row just adds one more.  And we
          # want to start at 1 instead of 0.
          $n = $j * $rows + $i + 1;
    
          ?><td><?= $n ?></td><?php 
        }
    
      ?></tr><?php
    
      }
    ?></table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a page which looks somewhat like this: http://www.drmichaelbogdan.com/plastic-surgery/ (I'm referring
I'm trying to use this library (which looks very nice) but I'm having difficulty
I have a Windows Azure Table Called ChannelsVideos which has been denormalized to hold
I'm trying to re-use a Java generic collection I wrote, looks a lot like
I am trying to create a single sign on process. The method I have
I'm trying to use an in-memory SQLite database to test my data layer which
I am trying to create pager which will sit in the center of the
I have a SQL which I am trying to run in Informix but it
I have a View that i am trying to use to fill a TableAdapter
Trying to create DIV containers out of a mysql results which each hold chunks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.