Jump to content

[SOLVED] Creating php code to put odd numbers in a table.


talksr

Recommended Posts

Basically, I would like php to create the numbers and insert them into a table in a web page.

 

Well, I gave you the code to generate the numbers...now all you have to do is generate the HTML you want. If you don't know how to do that, then give a description of how you want the table to look.

Link to comment
Share on other sites

This line

for ($i=3; $i<100; $i+=2){

 

Is telling $i to start at 3, increase by 2 each time the loop runs, and to run the loop 99 times (since you want all odd numbers up to 99.

 

   if ($cols == 5){
      echo '<tr>';
      $cols = 0;
   }

 

I set up a counter named $cols, this counts how many times the loop has run...so if it has run 5 times, then $cols equals 5.  So that code checks if the loop has run 5 times, and if it has, to create a new row (since you want 5 numbers per line). Then it starts the counter over for the next row.

 

Hopefully those make sense :)

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.