KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Selecting a single value from a table #1579

Open The O opened this topic on on Aug 19, 2020 - 4 comments

The O commented on Aug 19, 2020

I can see how to get datasets but how do I get a single value using a query and then assign it to a variable in php? E.g. for SQL query:

SELECT name FROM customers LIMIT 1;

I know I can assign to an array e.g. $result and then pick $result[0]. Is there a shorter way?

David Winterburn commented on Aug 20, 2020

If you meant using a general PHP way, please try:

$name = $mysqli->query("SELECT name FROM customers LIMIT 1")->fetch_object()->name; 

If you meant using KoolReport's datastore:

$name = $this->dataStore("customerNames")->pop()["name"];

Thanks!

The O commented on Aug 20, 2020

Does mysqli automatically use the same connection set by Koolreport?

Should we not (and is not safer to) be running pdo?

The O commented on Aug 20, 2020

Also seems to be no mention of pop method in your datasources documentation. Does a pop operation not also remove the item from the dataStore (opposite of push?)

David Winterburn commented on Aug 21, 2020

The pop() method only returns the on-top row of its datastore, then move to next row but doesn't remove the popped rows from the datastore's data (in this aspect it is different from PHP's array_pop). You can always call $ds->popStart() to come back to the first row.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None