如何在结果集中获取行计数和循环

I've recently gotten over my bad habit of using the deprecated mysql functions in favor of mysqli, and I'm having some issues.

Right now, I'm using something similar to the following:

$query = $conn->prepare("SELECT * FROM table WHERE cid = ?");
$query->bind_param('i', $id);
$query->execute();

And this is where I get stuck. In order to loop through the result, I use:

while ($row = $query->get_result()->fetch_assoc()) {
    //My code here
}

However, I need to determine the number of rows returned from the query before going through the results. To do this, I need to do the following:

$query->store_result();
$rows = $query->num_rows;

But I get errors when calling both get_result and store_result on the same query.. is there an easier way to do this? Am I overthinking things? I basically just want to determine if the result set has greater than x # of rows, and if so, loop through the results.

Thanks for any help.