I'm using the following code:
$wpdb->get_results("
SELECT * FROM " . $wpdb->prefix . "product_order
WHERE
rel = '" . $post["id"] . "' AND
`range` = '" . $range . "' AND
category = '" . $range . "'
");
echo $wpdb->num_rows;
num_rows returns 1 even though there is no rows in the database? Any ideas?
The variables I am putting in look fine. so it should be querying correctly.
global $wpdb;
$wpdb->get_results("
SELECT * FROM " . $wpdb->prefix . "product_order
WHERE
rel = '" . $post["id"] . "' AND
`range` = '" . $range . "' AND
category = '" . $range . "'
");
echo $wpdb->num_rows;
Now it returns numbers of rows select from above query and 0 if no row selected.....
if you JUST want the count (maybe for pagination total), it is faster to do:
global $wpdb;
$rows = $wpdb->get_results("
SELECT COUNT(*) as num_rows FROM " . $wpdb->prefix . "product_order
WHERE
rel = '" . $post["id"] . "' AND
`range` = '" . $range . "' AND
category = '" . $range . "'
");
echo $rows[0]->num_rows;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With