P粉7331667442023-08-01 13:54:41
In WordPress, by default, the get_results function returns an array of stdClass objects instead of an associative array. Therefore, you need to use the arrow operator (->) as an object property to access elements instead of using square brackets ([]) as an array index.
Make sure your table name ('students_list') is correct and actually exists in your database. If the table name changes or relies on WordPress prefix, you should use $wpdb->prefix . 'your_table_name'.
As a precaution, always check if $result is empty before doing a foreach loop to avoid potential problems.
For more detailed error information, consider enabling debugging in WordPress. You can do this by adding the following line to your wp_config.php file: define( 'WP_DEBUG', true );. This will provide more comprehensive error output for diagnostic purposes.