-1

After my function, I would like to retrieve the number of rows that the query of this function returns. Is it possible ? How ? Thanks

function rdvsList($user)
{
    $pdo = connexion();
    $sql = $pdo->prepare("SELECT * FROM rdvs WHERE idUser = :id AND date >= date(NOW()) AND (status = 'confirmed' OR status = 'refuse') ORDER BY date ASC");
    $sql->execute(["id" => $user]);
    return $sql->fetchAll();
}

I already know how to display each line:

$rdvList = rdvsList($_SESSION['user']);
foreach ($rdvList as $row) {
...
echo $row['object'];
...
}
Davidwys
  • 13
  • 3

1 Answers1

-1

use rowCount() after execute()

$sql->execute();
$count = $sql->rowCount();
Waad Mawlood
  • 727
  • 6
  • 10
  • Please close pages that can be resolved by pointing to a pre-existing Stack Overflow page. [The fundamental goal of closing duplicate questions is to help people find the right answer by getting all of those answers in one place.](https://stackoverflow.com/help/duplicates#:~:text=The%20fundamental%20goal%20of%20closing%20duplicate%20questions%20is%20to%20help%20people%20find%20the%20right%20answer%20by%20getting%20all%20of%20those%20answers%20in%20one%20place.) Answering dupes prevents the [Roomba](https://stackoverflow.com/help/roomba) from doing its important work. – mickmackusa Aug 11 '22 at 08:29