shortcodes, custom php and their errors

The answer is: function reservations_yesterday() { global $wpdb; $results = $wpdb->get_var (“SELECT SUM(`mattiscool`), booking_date FROM `wp_cbxrbooking_log_manager` WHERE `booking_date` = CURDATE() -1”); return $results; } add_shortcode(‘name’, ‘reservations_yesterday’);

wpdb->query returns different value to phpMyAdmin

You need to read the manual for the functions you’re using as all the information for how to debug is contained there. $wpdb-query() description is very clear. The return value is: (int|bool) Boolean true for CREATE, ALTER, TRUNCATE and DROP queries. Number of rows affected/selected for all other queries. Boolean false on error. As mentioned … Read more

Conditional formatting on data fetched from MYSQL

First a few notes: Shortcodes do accept arguments, so you could write [marks subject=”Biology”] (@see https://codex.wordpress.org/Shortcode_API) You should never ever pass raw data directly into a SQL statement, WordPress uses PDO, this means you can prepare statements. (@see https://developer.wordpress.org/reference/classes/wpdb/prepare/) Using the get_results will return an Array, object or null (@see https://developer.wordpress.org/reference/classes/wpdb/get_results/). There are many approaches … Read more