0

i created a new table inside my wordpress database called forms, this table consist of ID and names

i want to query all the list from this table using the wordpress $wpdb

this is my code below

<?php
    global $wpdb;
    $result = $wpdb->get_results ( "SELECT * FROM  $wpdb->forms" );
    foreach ( $result as $print ) {
          echo $print->ID.'<br/>';
   }
?>

but im only getting a text Array from my echo

1

you doing something wrong your $result query returns multidimensional array of rows and each row has an array of keys values, try this, not tested but will work.

<?php
global $wpdb;
$result = $wpdb->get_results ( "SELECT * FROM  $wpdb->forms" );
foreach ( $result as $key => $row ) {
      echo $row->ID.'<br/>';
}
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.