Just not understanding how to set up Category menus

44 posts by 5 authors in: Forums > CMS Builder
Last Post: September 22, 2009   (RSS)

By Codee - September 7, 2009

Chris, no problem BUT in the meantime I have a BURNING question -
I've been testing viewers with pulling the inventory data and display the list and details records. When I pull the manufacturer or model I get the record number for them instead of the actual name. Here's the code I'm using...and except for the if statement all the code on the page was generated by the code generator:
Here's the year, make, model code:
<?php if ($record['year']): ?>
<b/><?php echo $record['year'] ?>&nbsp;</b/>
<?php endif ?>

<?php if ($record['manufacturer']): ?>
<b/><?php echo $record['manufacturer'] ?>&nbsp;</b/>
<?php endif ?>

<?php if ($record['model']): ?>
<b/><?php echo $record['model'] ?></b/><br/><br/>
<?php endif ?>

Only the year comes up with the proper name...the manufacturer and model come up with their numeric record equivalents and I would like the name/title of the manufacturer and model to appear.

Thanks,

Re: [equinox69] Just not understanding how to set up Category menus

By Chris - September 7, 2009

Hi Terry,

What a coincidence! I've been working on a generic solution to both of these issues. I hope to have an elegant solution for you tomorrow, and if not, I'll have a slightly less elegant solution tomorrow that works just as well. :)
All the best,
Chris

By Chris - September 8, 2009

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'] ?>&nbsp;</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'] ?>&nbsp;</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

By Codee - September 8, 2009

Chris,
Thanks! Will work in and test the plugin you created shortly and get back to you.

BTW, will I have to redo these changes when I upgrade or is this becoming part of the next version?

By Codee - September 8, 2009

Chris,
I did all the steps down to the line you wrote:
"I hope this helps! Please let me know if you have any questions or run into any problems. "
and then tested it. It "mostly" worked. There is a series of index errors:
"Notice: Undefined index: parentNum in /home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php on line 660 Notice: Undefined index: parentNum in /home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php on line 660 Notice: Undefined index: parentNum in /home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php on line 660 Notice: Undefined index: parentNum in /home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php on line 660 Notice: Undefined index: depth in /home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php on line 675 Notice: Undefined index: depth in /home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php on line 685 Notice: Undefined index: depth in /home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php on line 699 Notice: Undefined index: depth in /home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php on line 703 Notice: Undefined index: depth in /home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php on line 675 Notice: Undefined index: depth in /home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php on line 685 Notice: Undefined index: depth in /home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php on line 699 Notice: Undefined index: depth in /home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php on line 703 Notice: Undefined index: depth in /home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php on line 675 Notice: Undefined index: depth in /home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php on line 685 Notice: Undefined index: depth in /home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php on line 699 Notice: Undefined index: depth in /home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php on line 703 Notice: Undefined index: depth in /home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php on line 675 Notice: Undefined index: depth in /home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php on line 685 Notice: Undefined index: depth in /home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php on line 699 Notice: Undefined index: depth in /home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php on line 703 "

I've attached a screenshot of the resulting error.

testing the other portion of the help you gave and will report back.
Attachments:

errorsnapshot_mfg.gif 73K

Re: [equinox69] Just not understanding how to set up Category menus

By Chris - September 8, 2009 - edited: September 8, 2009

Hmm. It sounds like you have set up one of your sections as a Category Menu? I know I suggested that at the top of this thread, but that was before I understood what you wanted to accomplish. To get this working, you'll need all four sections to be Multi Record.

On second thought, are you calling getCategories() instead of getRecords() somewhere? Since these are Multi Record sections and not Category Menus, you can't use getCategories().

If that doesn't help, please attach the PHP source code of that page and I'll have a look.
All the best,
Chris

By Codee - September 8, 2009

Hi Chris,
chris wrote: <I'm assuming you're working with a Detail viewer page for Inventory records, and your STEP 1 code looks like this: >

I got that to work for the detail page but had to axe out the stuff for equipment_type because it keeps erring (related to other error post?)...BUT the same issue occurs on the List viewer page. So, if you don't mind, how do I modify the top step 1 code on the list viewer page? Right now it reads:
list($inventoryRecords, $inventoryMetaData) = getRecords(array(
'tableName' => 'inventory',
'perPage' => '7',
));

thanks!

By Codee - September 8, 2009

Chris,
OK, I've simply restarted the coding process you gave for the left menu - it's working.

Just so you know, "equipment_types" is "equipment_type" on this side.

Now, your code for the detail page viewer is erroring with regards to equipment type. It happens whenever there is a 2-word named equipment type like "air compressors". Here's the error I get when I try to view the page:
"MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Compressors)) ORDER BY dragSortOrder DESC' at line 3 "

If I take the space out between "air compressors", changing it to "aircompressors" or "air-compressors" etc. the error goes away...is there a better fix?

Also, on the inventoryDetail.php page, what code do I use to display the equipment type? Using the following doesn't work:
<?php if ($record['equipment_type']): ?>
<b/><?php echo $record['equipment_type']['title'] ?>&nbsp;</b/>
<?php endif ?>

Thanks!

By GraphicLingoes - September 9, 2009

Hi Chris,

I got this to work the way I wanted to, thanks for the plugin, made my life easy. I was just wondering what is the injectionField' for? Are you referring to SQL Injection or are you actually creating a field on the fly at some point in the mysql database?

Thanks
Graphic Lingoes
www.graphiclingoes.com