Hi everyone, I am trying to run a select query using the results from an earlier successfull query.
See below -

                            $stmt = $conn->prepare("SELECT * FROM tab1 ORDER BY id DESC");
                            $total = $stmt->rowCount();

                            $cstmt = $conn->prepare("SELECT * FROM tab2 WHERE otdc_ref='$stmt->otdq_ordernum'");
                            $total = $cstmt->rowCount();                                                                        

                                while ($row = $stmt->fetchObject()) {

how is it possible to get the results of the 2nd query to be displayed, At the moment, only the results from the first query are being displayed,
Thanks in advance


it does not work because you are not accessing to the returned row when you call $stmt->otdq_ordernum.


$row = $stmt->fetch();

And then:


Or use a MySQL variable.

Also rowCount() in PDO, assuming you are using it, does not return the rows found in a SELECT statement, but only the rows affected by INSERT, UPDATE, DELETE & similar statements.