I wrote a function which is supposed to return the number of rows found in a SELECT query but it always either seems to return 0 or an array. I have been messing around with this for about an hour now and I still can't figure it out! I'm sure I'm doing something stupidly wrong.
The MySQL Table
+--------+-------------+---------------------+
| postid | ip | time |
+--------+-------------+---------------------+
| 1234 | 192.168.0.1 | 2014-01-29 14:27:02 |
| 5678 | 192.168.0.2 | 2014-01-29 14:27:02 |
+--------+-------------+---------------------+
PHP
### Search for IP in database
function postviews_get_ip($id, $ip) {
global $post, $wpdb;
$wpdb->get_results("SELECT * FROM $wpdb->wp_postviews_ips WHERE postid = $id AND ip = $ip");
$rowcount = $wpdb->num_rows;
return $rowcount;
}
postviews_get_ip($id, $_SERVER['REMOTE_ADDR']);
//both $id and $_SERVER['REMOTE_ADDR']) return the values I'm searching for in the database