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

Hello,

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:

<?php

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

Phil

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.

Apologies!

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:

<?php
$ages = range(10,300,10);
?>

<style>
.divTable{
    display:table;
    border-color: silver;
    border-style: solid;
    border-width: 2px;
    border-radius: 10px;
    padding: 5px;
}
.divTr{
    display:table-row;
}
.divTd{
    display:table-cell;
    padding:3px;
    vertical-align: middle;
}
</style>
<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>
    </div>
<?php
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>
    </div>\r\n";
}
?>
</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, networking, learning, and sharing knowledge.