So i need to create a php table that will take the age of the user (entered via a form) it will then show double the age and half the age. The rows should display the user's age +10 +20 etc.

I'm new to php so trying to get my head round a few things so have no idea how to do this. i know how to create the table but thats it. Any help is appreciated.

Recommended Answers

All 5 Replies


It would be a good idea if you atleast tried this yourself, even the smallest attempt would be beneficial since we're not here to do homework.

I don't clearly understand what you want, but, have a look at this:


    // Accept the users age
    $age = $_POST['age'];

    $half_age = $age / 2; // half the age
    $dble_age = $age*2; // double the age

I'm sure it's not as simple as that.. If you want to increment by 10 each time, then you can do that.. If you want to increment by the half age, or double age.. You can do that as well!


Thanks you! It's not homework, I'm at university and was styuding this throughout the year but didnt quite understand it so trying to do a few tasks myself to build up knowledge before i start placement.


So what is it your exactly trying to do? Do you want to increment by a particular number and then create a dynamic table that populates depending on the results?

No worries :)

what i was trying to do was the table was to have 6 tables, first row being the age the user has entered, then it doubled, then halved. eg. 30 60 15. The next row then being 40 80 20 then 50 100 25 etc. I have the first row completed but not sure i increment for the following rows.

Heres my take on it:

$ages = range(10,300,10);

    border-color: silver;
    border-style: solid;
    border-width: 2px;
    border-radius: 10px;
    padding: 5px;
    vertical-align: middle;
<div class='divTable'>
    <div class='divTr'>
        <div class='divTd'>Age</div>
        <div class='divTd'>Double</div>
        <div class='divTd'>Half</div>
        <div class='divTd'>age^2</div>
        <div class='divTd'>+10 - age/4</div>
        <div class='divTd'>age + 9001</div>
foreach($ages as $v){
    echo "
    <div class='divTr'>
        <div class='divTd'>{$v}</div>
        <div class='divTd'>".($v*2)."</div>
        <div class='divTd'>".($v/2)."</div>
        <div class='divTd'>".pow($v,2)."</div>
        <div class='divTd'>".($v+10-($v/4))."</div>
        <div class='divTd'>".($v+9001)."</div>

I find that you get better at solving problems with the more functions you are aware of, eg. range() was a newer one for me about a couple monhs ago and just practicing logic - foreach and arrays are really powerful imo

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.