$wpdb->get_results()
returns an array of rows from the queried table and not a mysqli_result object, so you can just use foreach
like so:
$result = $wpdb->get_results( $sql );
foreach ( $result as $row ) {
echo $row->correct_count;
// ...
}
And by default, each row is an object with the columns (<column name> => <column value>
) in the database table, but if you want the item be an associative array, then pass ARRAY_A
as the second parameter for $wpdb->get_results()
.
$result = $wpdb->get_results( $sql, ARRAY_A );
foreach ( $result as $row ) {
echo $row['correct_count'];
// ...
}
Please refer to the reference for further information.
Related Posts:
- Delete post revisions on post publish
- Is the regular ajax request method safe or I should use admin-ajax.php?
- Successful or Error Message after running mysql code in functions.php
- Insert all post IDs in new database table
- PHP code inside shortcodes
- WSoD being caused by this piece of code
- How to check if a meta value has already been assigned to any user?
- $wpdb->wp_users returning empty value for
- Multiple meta_key in one global $wpdb;
- How to use mysql LIKE with wpdb?
- making php value numeric
- SQL error with custom query
- Modify WooCommerce used to get all orders in dashboard
- How can I display a query in a page?
- How to set up an auto delete post?
- Fatal error: Call to undefined function mysql_connect()
- How to return number of found rows from SELECT query
- Set media upload attachment link to none and hide it in WP v3.5
- Fatal error: Call to undefined function plugin_dir_path()
- Switching wp_get_sites to get_sites
- One button to change all settings in theme customizer?
- Add custom image sizes to media uploader
- How to add default images into theme customizer image control?
- Is $hook a global variable in WordPress
- WordPress get pagination on wpdb get_results
- Custom Logo URL | Help me print the URL of the custom logo I inserted into my theme
- Include a php file from functions.php only to homepage
- How do I fetch all comments per post via WP REST API?
- Shortcode content output but not in correct place
- How to restrict page access to logged-in users?
- Handling Body class based on Template
- Is XAMPP faster than running LAMP in WSL on Windows 10? [closed]
- Adding Default Settings to Theme My Login plugin
- Get updated query results on page after insert in database
- Automatically adding new post categories to menu
- Get post id in a function when edit/add a post
- function to assign user role based on a field from usermeta
- get author_name from queried post
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- Pass php dynamic variable to shortcode
- How to split links generated into an xml sitemap to avoid exceeding 30 sec maximum execution time?
- Hacked WordPress website /Homepage redirect [closed]
- Refresh table data with Ajax
- Database query works fine outside WordPress
- How i can obtain all the post meta for a specific post as an array?
- Filtering a function’ output for a new continued function
- Shortcode to find and replace URL
- Deleting Certain terms from appearing on the front end as links
- first instantiated SimplePie object cosumes 5mb?
- Theme not calling Jquery properly
- Creating Database Table vs. Adding MetaData to Post & User
- Function Reference Documenting Template Tags for use in Custom Theme Templates?
- How to make jquery count down timer function manually editable
- Need php code’s output to display underneath a Divi Module
- WP_Query | IF within $args array | Help me only add specific arguments if the argument is not blank
- How to make function appear in sentence?
- How to define a variable already defined in a plugin function?
- woocommerce specific quantities for product
- woocommerce related product title length
- Custom query vars filters problem with pagination
- How to use AJAX in WordPress in MYSQL query?
- Query for user roles
- Use SCSSPHP to compile Theme Customizer Values into .SCSS files ready to compile to CSS
- Displaying Slider in Front Page (home) using Customizr Theme
- Is there a way to create a “copy post” link?
- Taxonomy term description with style, only if the description exists?
- Use of antispambot with $curauth->email
- Restrict post to current user in postmeta
- Passing in MySQL prepare statement parameter separately throwing error
- Database SQL query error
- copy fields value to another field
- posts_per_page displays only 2 posts instead of 4 posts
- MYSQL TIMESTAMP when adding DATE_FORMAT then the output is blank, PHP conflict?
- Get parent category name when only child category is applied to a product
- Updated Php version from 5.4 to 7.2 and getting “PHP installation missing the MySQL extension needed by WordPress”
- Store GA Client ID in User DB
- Adding product permalink on admin order page throwing error
- Before & After Content – After Content directly below Before Content when using require_once
- Access to “My Site” is missing from the admin bar
- How to redirect (301) trashed post to it’s parent taxonomy TERM ARCHIVE instead of 404 page
- Need help with format of nested array in MySQL
- How to call WordPress PHP file using external js file
- Site doesnt work once PHP changed to 7.1
- can’t delete a row from post_meta table
- use system script advertising in wordpress multisite
- Styling admin page rows in order of importance (checkboxes)
- Insert wordpress tags below posts via functions.php
- Help with my first Metabox helper class
- Splash pages on a high traffic site
- Pagenav Not appearing on custom Template
- ISOTOPE – Missing/Invalid Arguement Get Terms
- My title is showing after the shortcode
- Load a Header in wordpress
- Trouble figuring out how to get my button to submit comment
- Adding multiple conditional tags in a function?
- Submit cf7 form to cfdb as pdf/BLOB [closed]
- Why a class property becomes empty?
- Hide category by tag
- add_rewrite_rule image from /images/site2/favicon.ico to /favico.ico
- Background Tasks in a WP Cronjob?