It's a simple question, but no websites or resources out there seem to tell me the answer.
I have an sql query like below:
SELECT COUNT(id) FROM Events
Simple enough! How do I get the value? How do I go about running this query in PHP so I can print the result?
(By the way, I know how to print something row-by-row in a select statement, but all I need here is one value, and all online tutorials stop at this point and don't give me the PHP code. I've been looking for days! It's like I know how to drive - I just need someone to tell me where to find the car keys.)
=======
I'll explain my question more. A lot of people are pointing me to other pages (which I've seen) that don't actually explain HOW to get the data.
Here's my code so far:
$sql8 = "SELECT COUNT(ID) as counter FROM Events";
$result8 = $conn->query($sql8);
if ($result8->num_rows > 0) {
while($row8 = $result8->fetch_assoc()) {
echo $row8['counter'].".".$row8['COUNT(ID)'];
}
}
This WORKS, but I don't think this is the most efficient way to write it. How do I execute this query? That's the main part of my question. How I get the count from it works (thanks) but now it's a matter of writing it properly.
Thanks, Brendan