user5286438
user5286438

Reputation:

Checking with MySQL whether the number of rows of a table is less than (N + 8)

I have a check I'm trying to run for whether the number of rows in a table is less than N+8. The reason it's very messy is because I have to use the WordPress API and get_results function (https://developer.wordpress.org/reference/classes/wpdb/get_results/) to get everything from MySQL land to PHP land.

What I have is

$stillSomeLeft = ($wpdb->get_results($wpdb->prepare("SELECT COUNT(*) FROM $thisTable < (%d  + 8)", $_POST['numItemsLoaded']))) === true;

and $stillSomeLeft is always evaluating to false. Of course, since get_results returns an object corresponding to the result of the query, I have no way of knowing exactly what that object will be, but since the query would return true/false in MySQL land, I assume the PHP equivalent "object" will be the same.

Gotta love loosely-typed languages ...

Upvotes: 0

Views: 47

Answers (1)

Juan Carlos Oropeza
Juan Carlos Oropeza

Reputation: 48177

Your problem is the select statement

You only need

SELECT COUNT(*) FROM $thisTable

With that value you compare to N + 8 in your PHP.

Upvotes: 1

Related Questions