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");
                            $stmt->execute();
                            $total = $stmt->rowCount();

                            $cstmt = $conn->prepare("SELECT * FROM tab2 WHERE otdc_ref='$stmt->otdq_ordernum'");
                            $cstmt->execute();
                            $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

Ok,

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

Use:

$row = $stmt->fetch();

And then:

$row->otdq_ordernum;

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.

See:

Be a part of the DaniWeb community

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