Hi Terry,
I've developed a plugin which will make both of these jobs a snap. I've attached it to this forum post. Upload it to your server in /cmsAdmin/plugins, then login to your CMS Builder, go to Admin > Plugins, then Activate it.
I would like to create a menu on the left hand side of the pages the visitors see that will allow them to click on the manufacturers, models and equipment type...
First, let's add a section for "Equipment Type" and a field in your Inventory section to reference it:
Field Label: Equipment Types
Field Name: equipment_types
Field Type: list
Field Options:
Display As: pulldown (multi value)
List Options: Get options from database (advanced)
Section Tablename: equipment_type
Use this field for option values: num
Use this field for option labels: title
Okay, I imagine your left side menu will work as two separate lists. The first list will be your Manufacturers and Models. Generate a Viewer for your Manufacturers and you should have this in your STEP 1 code:
list($manufacturerRecords, $manufacturerMetaData) = getRecords(array(
'tableName' => 'manufacturer',
));
Let's replace that with the following:
// load all manufacturer records
list($manufacturerRecords, $manufacturerMetaData) = getRecords(array(
'tableName' => 'manufacturer',
'allowSearch' => false,
));
// load model records related to manufacturers
beta_lookupReferringRecords(array(
'sourceTable' => 'manufacturer',
'recordList' => &$manufacturerRecords,
'foreignTable' => 'model',
'foreignFields' => array('manufacturer'),
'injectionField' => 'models'
));
// load all equipment_type records
list($equipment_typeRecords, $equipment_typeMetaData) = getRecords(array(
'tableName' => 'equipment_type',
));
// load all inventory records
list($inventoryRecords, $inventoryMetaData) = getRecords(array(
'tableName' => 'inventory',
'allowSearch' => true,
));
And replace your STEP 2 code with this:
<h3>Manufacturers and Models</h3>
<ul>
<?php foreach ($manufacturerRecords as $manufacturer): ?>
<li>
<a href="?manufacturer=<?php echo $manufacturer['num'] ?>"
<?php echo (@$_REQUEST['manufacturer'] == $manufacturer['num']) ? ' style="font-weight: bold"' : ''; ?>>
<?php echo $manufacturer['title'] ?>
</a>
<ul>
<?php foreach ($manufacturer['models'] as $model): ?>
<li>
<a href="?model=<?php echo $model['num'] ?>"
<?php echo (@$_REQUEST['model'] == $model['num']) ? ' style="font-weight: bold"' : ''; ?>>
<?php echo $model['title'] ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</li>
<?php endforeach; ?>
</ul>
<h3>Equipment Types</h3>
<ul>
<?php foreach ($equipment_typeRecords as $equipment_type): ?>
<li>
<a href="?equipment_type=<?php echo $equipment_type['num'] ?>"
<?php echo (@$_REQUEST['equipment_type'] == $equipment_type['num']) ? ' style="font-weight: bold"' : ''; ?>>
<?php echo $equipment_type['title'] ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<h3>Inventory</h3>
<ul>
<?php foreach ($inventoryRecords as $inventory): ?>
<li><a href="<?php echo $inventory['_link'] ?>"><?php echo $inventory['title'] ?></a></li>
<?php endforeach; ?>
</ul>
I hope this helps! Please let me know if you have any questions or run into any problems.
When I pull the manufacturer or model I get the record number for them instead of the actual name.
I'm assuming you're working with a Detail viewer page for Inventory records, and your STEP 1 code looks like this:
list($inventoryRecords, $inventoryMetaData) = getRecords(array(
'tableName' => 'inventory',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$inventoryRecord = @$inventoryRecords[0]; // get first record
// show error message if no matching record is found
if (!$inventoryRecord) {
print "Record not found!";
exit;
}
Replace that with the following:
// load inventory record selected by user in URL
list($inventoryRecords, $inventoryMetaData) = getRecords(array(
'tableName' => 'inventory',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
// show error message if no matching record is found
if (!@$inventoryRecords[0]) {
print "Record not found!";
exit;
}
$inventoryRecord =& $inventoryRecords[0]; // get first record
// load referenced records for our fields
beta_lookupRelatedFields(array(
'table' => 'inventory',
'recordList' => &$inventoryRecords,
'fieldList' => array(
'manufacturer', 'model' => 'model', 'equipment_types'
),
));
Then, when displaying your content, instead of doing this:
<?php if ($record['manufacturer']): ?>
<b/><?php echo $record['manufacturer'] ?> </b/>
<?php endif ?>
<?php if ($record['model']): ?>
<b/><?php echo $record['model'] ?></b/><br/><br/>
<?php endif ?>
do this:
<?php if ($record['manufacturer']): ?>
<b/><?php echo $record['manufacturer']['title'] ?> </b/>
<?php endif ?>
<?php if ($record['model']): ?>
<b/><?php echo $record['model']['title'] ?></b/><br/><br/>
<?php endif ?>
Phew! Please let me know if you have any trouble getting anything working or have any more questions.
All the best,
Chris