WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Can't get wpdb query formatted in table tr td etc (3 posts)

  1. mobilemeneer
    Member
    Posted 1 year ago #

    Hi Guys,

    I'm using a custom table in my wordpress database and am using wpdb to query the complete content of this table.

    This is what i am using:

    global $wpdb;
    $allposts= $wpdb->get_results("SELECT * FROM test", ARRAY_A);
    echo '<table>';
    foreach ($allposts as $key => $value){
    echo '<tr>';
    echo '<th>' .$value["test"]. '</th>';
    echo '<th>' .$value["test1"]. '</th>';
    echo '<th>' .$value["test2"]. '</th>';
    echo '<th>' .$value["test3"]. '</th>';
    echo '<th>' .$value["test4"]. '</th>';
    echo '</tr>';
    }
    echo '</table>';

    Unfortunately i can't get this data in the correct format. All de information is displayed without enters and doesn't seem to accept my table, th etc.

    What am i doing wrong?

    I'm using a plugin to be able to enter php code in my wordpress page.

    Any help will be appriciated, Many thanks in advance.

  2. mobilemeneer
    Member
    Posted 1 year ago #

    I solved the issue. It was caused by a plugin named "Use php in your posts" or st.

    So don;t use it, just stick to the good old Exec_PHP plugin to use php code on the pages.

    This issue really got me stuck for a week.

  3. dsanderling
    Member
    Posted 1 year ago #

    Actually you can do it with the "Allow PHP in Posts and Pages" plugin you speak of. (I'm using the same one. ;)) You just have to use square brackets instead of angle brackets, so WP doesn't do it's black magic on your html tags.

    Example:
    echo '[table cellpadding="0" cellspacing="0"]';
    foreach($myjson->beefs as $beef)
    {
    echo '[tr][td]' . $beef->name . '[/td][td]' . $beef->unit_price . '[/td][/tr]';
    }
    echo '[/table]';

Topic Closed

This topic has been closed to new replies.

About this Topic