• Resolved mobilemeneer

    (@mobilemeneer)


    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter mobilemeneer

    (@mobilemeneer)

    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.

    dsanderling

    (@dsanderling)

    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]’;

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can't get wpdb query formatted in table tr td etc’ is closed to new replies.