3 Ways to Retrieve and show Data from the SQL Database in WordPress - Knowboard

PHOTO EMBED

Tue Oct 25 2022 11:31:33 GMT+0000 (Coordinated Universal Time)

Saved by @kalehm

USE GET_VAR() TO RETURN A SINGLE VALUE
<?php
$customer_count = $wpdb->get_var(“SELECT COUNT(*) FROM laundry_customers;”);
echo ‘<p>Total customer: ‘ . $customer_count . ‘</p>’;
?>


USE GET_ROW() TO RETURN A SINGLE ROW OF DATA
<?php
$mycustomer = $wpdb->get_row('SELECT * FROM laundry_customers WHERE ID = 1');
echo $mycustomer -> customer_name;
?>


USE GET_RESULTS() TO RETURN MULTIPLE ROWS OF DATA
<?php
$allcustomers = $wpdb->get_results('SELECT customer_name, customer_id FROM laundry_customers WHERE status = 1');
foreach ($allcustomers as $singlecustomer ) {
echo '<p>' .$singlecustomer->customer_name. '</p>';
echo '<p>' .$singlecustomer->customer_id. '</p>';}
?>
content_copyCOPY

https://www.knowboard.de/3-ways-to-retrieve-and-show-data-from-the-sql-database-in-wordpress/