jquery get value of table cells in column, add values together and output on page

admin

Administrator
Staff member
This may seem a bit of bizarre question, and I'm not sure if it's possible.

I have created a HTML table in wordpress, and have built a PHP loop to output post data in table format.

I am using this <a href="http://tablesorter.com/docs/" rel="nofollow">jQuery table sorted plugin</a> to make it a sortable table.

But my question is, is it possible using jQuery to add up all the numerical values in my table
Code:
&lt;th&gt;Hours&lt;/th&gt;
column and output the result?

If a class needs to added to the
Code:
&lt;td&gt;&lt;?php echo get_post_meta($post-&gt;ID, 'Labour Time Hours', true); ?&gt;&lt;/td&gt;
cell then that's cool, it will not affect the tablesorter.

Then I would like to output the result in my table footer cell.

Is this possible? I can't seem to find anything on google but I'm probably search for the wrong term.

Thanks

<strong>MY WORDPRESS LOOP GENERATING TABLE CONTENT</strong>

Code:
&lt;?php 

        $data = new WP_Query(array(

        'post_type'         =&gt; 'job',
        'order'             =&gt; 'ASC',
        'posts_per_page'    =&gt; -1,
        'orderby'           =&gt; 'date'

)); ?&gt;

&lt;?php if ($data-&gt;have_posts()) : ?&gt;

&lt;table id="myTable" class="tablesorter"&gt; 

    &lt;thead&gt; 

        &lt;tr&gt; 

            &lt;th&gt;Date&lt;/th&gt; 
            &lt;th&gt;Job Title&lt;/th&gt; 
            &lt;th&gt;Category&lt;/th&gt; 
            &lt;th&gt;Hours&lt;/th&gt; 

        &lt;/tr&gt; 

    &lt;/thead&gt; 

    &lt;tbody&gt; 

        &lt;?php while ($data-&gt;have_posts()) : $data-&gt;the_post(); ?&gt;

        &lt;tr&gt; 

            &lt;td&gt;&lt;?php the_time('Y/m/d'); ?&gt;&lt;/td&gt; 
            &lt;td&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" title="View Job" &gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/td&gt; 
            &lt;td&gt;&lt;?php the_category(', ') ?&gt;&lt;/td&gt; 
            &lt;td&gt;&lt;?php echo get_post_meta($post-&gt;ID, 'Labour Time Hours', true); ?&gt;&lt;/td&gt; 

        &lt;/tr&gt; 

        &lt;?php endwhile; ?&gt;

    &lt;/tbody&gt;

    &lt;tfoot&gt;

        &lt;tr&gt;

            &lt;td&gt;&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
            &lt;td&gt;&lt;!-- Total to go here --&gt;&lt;/td&gt;

        &lt;/tr&gt;

    &lt;/tfoot&gt;

&lt;/table&gt;

&lt;?php unset($data); endif; wp_reset_query(); ?&gt;