this is my code

$sql = "SELECT * FROM `sale_history` WHERE `date` BETWEEN :fromdate AND :todate";
    $stmt = $PDO->prepare($sql);
    $stmt->bindParam(':fromdate', $_POST['fromdate'], PDO::PARAM_STR);
    $stmt->bindParam(':todate', $_POST['todate'], PDO::PARAM_STR);
    $stmt->execute();
    $total = $stmt->rowCount();
    while ($row = $stmt->fetchObject()) {
        echo "$row->date"; 
        echo "$row->product"; 
        echo "$row->username"; 
        echo "$row->quantity";
    }

but its not working, where is the mistake i did?

Re: How to search between two dates in PDO, Please help me. 80 80

For some reason the C++ like bindParam is looking better to most than the simpler question mark. For some reason you use fetchObject although it isn't really an object but an anonymous one. For some reason you echo it with double quotes. None of those would be an error. But the "not working" could mean a lot , what do you mean ? Do you get an error ? What this error is ? Is it simply not echoing anything ? Also provide us what the $PDO is .

Re: How to search between two dates in PDO, Please help me. 80 80
Member Avatar

<sidenote>
Using rowCount() for select queries / ps is not advised. There are a couple of methods that could be used instead - see http://php.net/manual/en/pdostatement.rowcount.php
</sidenote>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.