So further to a previous question, I've updated my code to the following
$stmt = $conn->prepare("SELECT count(id) FROM activities WHERE userId = ? AND status = ? AND DATEDIFF('$date', next_due) >= 1");
$stmt->bind_param("ss", $userId, $status);
$stmt->execute();
$stmt->store_result();
$numrows = $stmt->num_rows;
echo $numrows;
It no longer throws an error, but returns $numrows as 1, however I know the number of rows returned should be 2 (I know it should be 2 as I have 2 identical rows in the table for testing purposes). I've tried SELECT count(*)
, but that also throw a 1 at me.
COUNT()
will always return 1 row. either select the result content or use select id....
and then $stmt->num_rows
on the full query
This will return number of rows
$stmt = $conn->prepare("SELECT count(id) FROM activities WHERE userId = ? AND status = ? AND DATEDIFF('$date', next_due) >= 1");
$stmt->bindParam('ss', $userId, $status);
$stmt->execute();
$numrows = $stmt->fetchColumn();
Thanks for the suggestions. In the end I went with the following;
$stmt = $conn->prepare("SELECT * FROM activities WHERE userId = ? AND status = ? AND last_completed != ? AND DATEDIFF(?, next_due) >= 1");
$stmt->bind_param("ssss", $userId, $status, $null, $date);
$stmt->execute();
$result = $stmt->get_result();
echo $result->num_rows;
?>