I have a web application in php. where users can buy packages and admin can see how many sales each package have. right now I'm getting total sales by counting the rows from the payments table. to get the most bought package I think I have to count the rows in payments table in the database and return the id of of most bought package. but I don't to go with this?
Current Statement Which Get Package Sales from Id:
$sql = "SELECT COUNT(*) AS totalSales FROM ph_paypal_payments WHERE packageId = ?";
$stmt = mysqli_stmt_init($connection);
if (!mysqli_stmt_prepare($stmt, $sql)) die ("Prepare failed: " . mysqli_stmt_error($stmt));
mysqli_stmt_bind_param($stmt, "i", $packageId);
mysqli_stmt_execute($stmt);
return mysqli_fetch_assoc(mysqli_stmt_get_result($stmt))['totalSales'];