WordPress.org

Support

Support » Plugins and Hacks » [Resolved] table shortcode

[Resolved] table shortcode

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Michael Simpson

    @msimpson

    This is not an elegant way, but you can do it using cfdb-html:

    – Put you own TABLE, THEAD, TR, TH tags in your post, followed by TBODY
    – followed by a cfdb-html short code that output TR, TD element for each row
    – After the short code, put in closign /TBODY /TABLE tags

    You choose the names you want in our TH tags

    First of all thank you for the advise. I tried this but the Header Text is displayed in every row.
    Here is my code. (Short)

    <table border="1">
    <thead>
    <tr>
    <th>Name</th>
    <th>Surname</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td>${text-708}</td>
    <td>${your-name}</td>
    </tr>
    
    </tbody>
    </table>

    Probably it is my mistake but I can not figure it out.

    Plugin Author Michael Simpson

    @msimpson

    Put that stuff outside the shortcode

    <table border="1">
    <thead>
    <tr>
    <th>Name</th>
    <th>Surname</th>
    </tr>
    </thead>
    <tbody>
    [cfdb-html form="your-form"]
    <tr>
    <td>${text-708}</td>
    <td>${your-name}</td>
    </tr>
    [/cfdb-html]
    </tbody>
    </table>

    Thank you for the solution. It worked great.

    Would it be possible to calculate the summary of a specific collumn? I have for example a collumn that displays a choise from a dropdown menu. I know it is a text but the first character is arithmetic.

    Plugin Author Michael Simpson

    @msimpson

    If you want to compute a sum, then you need to do this as a create your own short code instead of using cfdb-html. Here is some code to get you started. Change ‘some-column’ to match your column name.

    require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CFDBFormIterator.php');
    $exp = new CFDBFormIterator();
    $exp->export($atts['form'], $atts);
    echo '<table border="1">
    <thead>
    <tr>
    <th>Name</th>
    <th>Surname</th>
    </tr>
    </thead>
    <tbody>';
    
    $summary = 0;
    while ($row = $exp->nextRow()) {
        echo '<tr>';
        echo '<td>'. $row['text-708'] . '</td>';
        echo '<td>'. $row['your-name'] . '</td>';
        echo '</tr>';
        // first character of string is number
        $summary = $summary + substr($row['some-column'], 0, 1);
    }
    
    echo '</tbody></table>';
    echo "$summary";

    Thanks a lot. It was very helpful. Finally I managed to have a sum of the columns.
    However I want to improve it by add the summary of the column in the last entry of the specific row.
    Is this possible?

    Hello. Is it possible to create for example 3 different tables instead of one that are assigned each to a choice of a radio button? Lets say place of delivery.
    I tried to put it after while a constraint but didn’t worked.
    Any ideas

    Plugin Author Michael Simpson

    @msimpson

    I suppose so. The template code for “create your own short code” basically shows you how to get and loop through the data. You can write your own PHP code there to create different tables or anything you want based on the data you see. It’s up to you to write the code.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Resolved] table shortcode’ is closed to new replies.