I'm trying to create a simple Resident Directory for our homeowners association. We previously used Ari Data Tables, with a custom table, but that extension is not J4 compatible and no indication it ever will be.
I added Users Fields for "Lot", "Address", and "Phone" and uploaded CSV files to populate the #__fields_values table.
Using https://regularlabs.com/sourcerer I added the following to a "Directory" article:
Code: Select all
<?php $query = $db->getQuery(true);
$query
->select('f.title')
->from($db->quoteName('#__fields', 'f'))
;
$db->setQuery($query, 0, 0);
$fv_list = $db->loadObjectList();
$q1 = $db->getQuery(true);
$q1
->select('u.id, u.name, f.title, fv.value')
->from($db->quoteName('#__users', 'u'))
->join('INNER', $db->quoteName('#__fields_values', 'fv') . ' ON ' . $db->quoteName('fv.item_id' ) . ' = ' . $db->quoteName('u.id'))
->join('INNER', $db->quoteName('#__fields', 'f') . ' ON ' . $db->quoteName('fv.field_id') . ' = ' . $db->quoteName('f.id'))
->order('`name` ASC')
;
$db->setQuery($q1, 0, 0);
$fields = $db->loadObjectList();
print_r($fields);
foreach ($fields as $fv)
{
$name = $fv->name;
$list[$name][0] = $name;
$list[$name][$fv->title] = $fv->value;
}
return (array($fv_list, $list));
?>
<table class="table table-striped">
<thead>
<tr>
<th>Lot</th>
<th>Name</th>
<th>Address</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
<?php
if(mysql_num_rows($list)==0 ){
echo '<tr><td colspan="4">No Rows Returned</td></tr>';
}
else {
while($row = mysql_fetch_assoc($list) ) {
echo "<tr><td>{$row['lot']}</td><td>{$row['name']}</td><td>{$row['address']}</td><td>{$row['phone']}</td></tr>\n";
}
}
?>
</tbody>
</table>
Any suggestions would be appreciated.
Kindly,
Andy