0
votes

I am currently developing a tool and part of it calculates employees. I want to be able to get 12 numbers of thier row from different coloumns...

E.G.

table {
    font-family: arial, sans-serif;
    border-collapse: collapse;
    width: 100%;
}

td, th {
    border: 1px solid #dddddd;
    text-align: left;
    padding: 8px;
}

tr:nth-child(even) {
    background-color: #dddddd;
}
<table>
  <tr>
    <th>Name</th>
    <th>Data 1</th>
    <th>Data 2</th>
    <th>Data 3</th>
    <th>Data 4</th>
    <th>Data 5</th>
    <th>Data 6</th>
    <th>Data 7</th>
    <th>Data 8</th>
    <th>Data 9</th>
    <th>Data 10</th>
    <th>Data 11</th>
    <th>Data 12</th>
  </tr>
  <tr>
    <td>Alfreds Futterkiste</td>
    <td>67</td>
    <td>34</td>
    <td>67</td>
    <td>34</td>
    <td>67</td>
    <td>34</td>
    <td>67</td>
    <td>34</td>
    <td>34</td>
    <td>67</td>
    <td>34</td>
    <td>67</td>
  </tr>
</table>

How to I add all of those together to make one number in php and display it on a dashboard? (Connects to MYSQL)

1
How is that table created? Is it generated through php? - verjas
No, manual imput through php my admin - WPS Team
Company, that specializes in tailoring needs - WPS Team
The only php generated code would be if they changed the numbers through thier settings. - WPS Team
PHP is a server side language. You should use it to work with data on the server side - e.g. sum the result of a database query and display the number by generating it into the html. In your case it looks like this is a static table, so it would be better to do the math on the client, using JavaScript. - Miklós Tóth

1 Answers

0
votes

You can use jquery to get all td value and concate that and pass it to php file using ajax.

$('#mytable td').each(function() {
    var cellText += $(this).html();    
});

then pass this value to ajax call.