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 7677671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:28:32+00:00 2026-05-31T17:28:32+00:00

I’m currently working on a dynamic table below: echo ‘<table border=1>’; echo ‘<tr align=center

  • 0

I’m currently working on a dynamic table below:

echo '<table border=1>';
echo '<tr align="center" width="140"><td>column 1 &rarr;
<br />&darr; column 2</td>';
echo "<td width='70'>{$c1}</td>";
echo "<td width='70'>{$c2}</td>";
echo "<td width='70'>{$c3}</td>";
echo "<td width='70'>{$c4}</td>";
echo "<td width='70'>{$c5}</td>";
echo '</tr>';
for ($i = $min; $i <= $max; $i+=5) {
    echo '<tr align="center">';
    echo '<td>'.$i.'</td>
    <td>'.$c1*$i.'</td>
    <td>'.$c2*$i.'</td>
    <td>'.$c3*$i.'</td>
    <td>'.$c4*$i.'</td>
    <td>'.$c5*$i.'</td>';
    echo '</tr>';
}
echo '</table>';

I was just wondering if there was a more effective less time-consuming method of generating it?

The table is created from the following inputs

min, max, c1, c2, c3, c4, c5

where if for example:

min=30, max=45, c1=5, c2=10, c3=15, c4=20, c5=25

the table might look something like:

enter image description here

Thanks in advance!

  • 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-05-31T17:28:33+00:00Added an answer on May 31, 2026 at 5:28 pm

    I would take a bit different approach. At first I don’t like the idea of having calculations (even simple ones) and view/result/html code mixed. So I would separate those tasks. Normally in most bigger applications this kind of table generation would not even be possible (like MVC frameworks) or is at least not preferred. Also I moved out the styling of the table.

    Next to that I don’t like the numbered values, a list of data looks like an array. I have not enough meta information whether that’s correct so I just made it an array since it looks to make sense. The amount of columns is flexible now also.

    View code (so PHP) I always try to keep as compact as possible but readable. Mostly simple code, not many loops, not many different functions just basics. So not a for loop with a specific step because it is not relevant. The view part should just show the data as it gets the data.

    <?PHP
    
    //settings
    $min=30;
    $max=45;
    $step=5;
    $cols=array(5,10,15,20,25);
    
    //result array
    $data=array();
    
    //data calculation
    for($i = $min; $i <= $max; $i+=$step) {
        foreach($cols AS $col => $val) {
        $data[$i][$col]=$val*$i;
    
        }
    }
    
    //html generation
    ?>
    
    <style type="text/css">
        th, td {
            text-align: center;
            vertical-align: top;
        }
    </style>
    <table border=1>
        <thead>
            <tr>
                <th scope="row">column 1 &rarr;</th>
                <?PHP
                    foreach($cols AS $val) {
                        echo '<th rowspan=2 scope="col">'.$val.'</th>';
                    }
                ?>
            </tr>
            <tr>
                <th scope="col">&darr; column 2</th>
            </tr>
        </thead>
        <tbody>
            <?PHP foreach($data AS $i => $row) { ?>
                <tr scope="row">
                    <td><?PHP echo $i; ?></td>
                    <td><?PHP echo implode('</td><td>', $row); ?></td>
                </tr>
            <?PHP } ?>
        </tbody>
    </table>
    

    Hope parts are useful for your project. Hope there are some. I like to write out quite lots of indents / tabs / newlines but you can always style the HTML as you want off course. Next to that I also always add table head, body and scopes which is different from your question but gives the same output in terms of layout off course as asked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
Does anyone know how can I replace this 2 symbol below from the string
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.