The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Retrieving details from a Database to table
#17
>There are plenty of times I think there will ALWAYS be results and then I break something

I recommend to write:

Code:
if (!$db->error() && $db->count()>0)

or to have an empty result array in case of error so that foreach will not happen:

Code:
$array = !$db->error() ? $db->results(true) : [];
Code:
foreach ($array as $item) {};

>Assigning the query to a variable lets me get both a count and results or first

You can just do this:

Code:
$first = $db->query($sql)->first();
Code:
$count = $db->count();
  Reply


Messages In This Thread
Retrieving details from a Database to table - by faguss - 07-13-2017, 07:42 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)