custom table problem
-
I created a new table within my WordPress database called wp_my_table. Then I populated the table with a few rows. I did all this from myphpadmin.
I am trying to display data from the new table on a page using the EXEC PHP plugin.
First thing I did was test if the table exists using the following.global $wpdb;
$table_name = $wpdb->prefix . “my_table”;
if ( $wpdb->get_var(‘SHOW TABLES LIKE ‘ . $table_name) != $table_name ){some random outputs}
This helped determine that the table exists and is recognized from the page on which I want to display the data.
Then I went to display something from the new table using the following:global $wpdb;
$table_name = $wpdb->prefix . “my_table”;$result = $wpdb->get_results(“SELECT * FROM $table_name”);
foreach ($result as $theresults) {
$tableid = $theresults->id;
echo $tableid;
}For some reason it was not working. At this point I tried to output the size of the $result.
$sizeofresult = sizeof($result);
echo $sizeofresult;
This returned zero. Seems that it is recognizing the table but not the populated rows within the table. When I try all of the above with wp_posts it works fine.
Not sure what the problem is with the new table. Any help would be greatly appreciated.
Thanks!
- The topic ‘custom table problem’ is closed to new replies.