GePraxa GePraxa - 1 month ago 5x
MySQL Question

Get query data without foreach

Currently I make my query like this:

function Data() {
$db = DB::getInstance();
$query = $db->query("SELECT * FROM users");
$results = $query->results();
return ($results);
$listdata = Data();

And when I want to see my information I have something like this:

<div class="container">
<div class="row">
<?php foreach ($listdata as $v1) { ?>
<?php } ?>


But if I want to put information see for example in the footer of the page I have to open a new

As I can transform this code to open the query to the top of the page and simply llabar variables where I want without opening another

Even better would defeat the function, I just want to put the query and data wherever.

Thank you!


You could try echo $listdata[0]->column_name thou this will print only the first to be precise use a where clause in your sql statment

Edit: It will print only the first index in the array that contains the Fetched Data