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
#7
Not sure what you mean. Something like that?

Code:
<?php echo $customers[0]['customer_id'] ?>

If you're reusing code then you could :
  • copy the table code to a separate file and use
    Code:
    include "separate_file.php"
  • or enclose the code into a function which you'd call when you need it

Code:
function get_customers_table() {
Code:
$html = "";

Code:
$db->findAll("customers");
Code:
$exclude = ["id","lname","password"];
Code:
$halve = ["fname"];

Code:
if (!$db->error() && $db->count()>0) {
Code:
$customers = $db->results(true);
Code:
$html .= "<TABLE CLASS=\"table\"><TR>";

Code:
foreach ($customers[0] as $key=>$value)
Code:
if (!in_array($key,$exclude))
Code:
$html .= "<TH>$key</TH>";

Code:
$html .= "</TR>";

Code:
foreach ($customers as $customer) {
Code:
$html .= "<TR>";

Code:
foreach ($customer as $key=>$value)
Code:
if (!in_array($key,$exclude)) {
Code:
$html .= "<TD>";
Code:
if (in_array($key,$halve))

Code:
$html .= substr($value, 0, strlen($value)/2);
Code:
else
Code:
$html .= "$value";

Code:
$html .= "</TD>";
Code:
}

Code:
$html .= "</TR>";
Code:
}

Code:
$html .= "</TABLE>";
Code:
}
Code:
return $html
Code:
}
Code:
echo get_customers_table();
  Reply


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

Forum Jump:


Users browsing this thread: 4 Guest(s)