Hi Everyone, I have the following script / select that is displaying all fields from my database - But only if i use {$row->field_name} in the output while loop -

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

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

                                            //$opvar = $row['mchq_var'];                                            

                                    echo "
                                        <tr>
                                          <td>{$row->mchq_var}</td>                                   
                                        </tr>                                                                                                                                                   
                                         ";

How would it be possible for me to use the $opvar variable in the table row instead of having to use {$row->mchq_var}
What is it that I am missing?

Thanks

Member Avatar for diafol

rowCount is not meant for SELECT queries. Use the SELECT COUNT(*) FROM table if you need an absolute count or count the from a fetch.

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.