Let’s say my resulting recordset is as follows:
Emp_ID ID Ability Rating
------ -- ------- ------
NULL DRI Driving NULL
NULL TYP Typing NULL
NULL GRA Graphics NULL
NULL VID Video NULL
NULL GAM Gaming NULL
while another case could be:
Emp_ID ID Ability Rating
------ -- ------- ------
15 DRI Driving 7
15 TYP Typing 6
15 GRA Graphics 8
15 VID Video 7
15 GAM Gaming 10
or:
Emp_ID ID Ability Rating
------ -- ------- ------
22 DRI Driving 4
NULL TYP Typing NULL
NULL GRA Graphics NULL
22 VID Video 8
22 GAM Gaming 5
What’s my least costly way in PHP to check if Emp_ID is all NULL like the first one?
Emp_ID is BIGINT(20) UNSIGNED (and Rating is TINYINT(2) UNSIGNED) in MySQL. The recordset is returned by $wpdb_custom->get_results().
Since you can’t edit the query, the best you can do is just iterate over the results checking for null. But the important thing is to
breakwhen you find a non-null row. At that point you know that not all rows are null, so don’t bother iterating over the remaining rows.