07-09-2017, 07:42 AM
Not sure what you mean. Something like that?
If you're reusing code then you could :
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:
elseCode:
$html .= "$value";Code:
$html .= "</TD>";Code:
}Code:
$html .= "</TR>";Code:
}Code:
$html .= "</TABLE>";Code:
}Code:
return $htmlCode:
}Code:
echo get_customers_table();