How do i dynamically populate a drop down menu from one of my fields

19 posts by 4 authors in: Forums > CMS Builder
Last Post: July 16, 2009   (RSS)

By blillie - July 9, 2009

Can someone help me to dynamically populate my drop down menus on my search page so i don't have to manually put in new code to match the categories that I'm adding on the backend?

Any help would be very much appreciated...

You can see the search page at www.fanmarketplace.com/finddeals.php

thx in advance!!!

Brian

Re: [blillie] How do i dynamically populate a drop down menu from one of my fields

By Damon - July 10, 2009

Hi Brian,

Here is a code example for you:

Based on having a Categories section that use the Title field for the names.

<?php
require_once "/path/to/your/viewer_functions.php";
list($categoriesRecords, $categoriesMetaData) = getRecords(array(
'tableName' => 'categories',
'allowSearch' => '0',
));
?>

<!-- ADD THIS SELECT CODE INTO YOUR SEARCH FORM -->
<select>
<option value="">Any</option>
<?php foreach ($categoriesRecords as $record): ?>
<option value="<?php echo htmlspecialchars($record['title']) ?>"><?php echo htmlspecialchars($record['title']) ?></option>
<?php endforeach; ?>
</select>


Give this a try and let me know how you work out.
Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Damon] How do i dynamically populate a drop down menu from one of my fields

By blillie - July 10, 2009

I'm still having trouble... here is the error i'm getting:


Fatal error: Call to undefined function: getrecords() in /home/fanmarke/public_html/finddeals2.php on line 3



===================

Here is the code I used:

<?php
require_once "http://www.fanmarketplace.com/cmsAdmin/lib/viewer_functions.php";
list($categoryRecords, $categoryMetaData) = getRecords(array(
'tableName' => 'category',
'allowSearch' => '0',
));
?>



and then for the search field i used:


<select>
<option value="">Any</option>
<?php foreach ($categoryRecords as $record): ?>
<option value="<?php echo htmlspecialchars($record['title']) ?>"><?php echo htmlspecialchars($record['title']) ?></option>
<?php endforeach; ?>
</select>



I changed where you had "categories" to "category" as that is the Field Name on the backend.


I'm testing it on this page: www.fanmarketplace.com/finddeals2.php

thx

Brian

Re: [blillie] How do i dynamically populate a drop down menu from one of my fields

By Damon - July 10, 2009

Hi again,

You are using the URL here:
require_once "http://www.fanmarketplace.com/cmsAdmin/lib/viewer_functions.php";
when you need to be using the server path instead.

Use the Code Generator to find out the correct path:
Admin > Section Editors - modify Category then click the "Viewer Code Generator" button.

Once you have the right path to the view_functions.php file, everything should work.
Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [blillie] How do i dynamically populate a drop down menu from one of my fields

By Damon - July 10, 2009

Try copying all the header code from the "code generator" again. It is probably a small typo or something missing.

If that doesn't work can you reply with your page as an attachment so I can look at the code.
Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Damon] How do i dynamically populate a drop down menu from one of my fields

By blillie - July 10, 2009

i can't find anything wrong with it... here is the file as an attachement.

thx

Brian
Attachments:

finddeals2.php 12K

Re: [blillie] How do i dynamically populate a drop down menu from one of my fields

By Dave - July 10, 2009

Is your tablename called 'category' or 'categories' or something else?
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] How do i dynamically populate a drop down menu from one of my fields

By blillie - July 10, 2009

It's in the Listings... the Field Label is "Product Category" and the Field Name is "category"

do you want me to email you the login and pw to access the backend so you can see what i'm seeing?

thx

Brian

Re: [blillie] How do i dynamically populate a drop down menu from one of my fields

By Dave - July 10, 2009

The tablename should be listed under Admin > Section Editors. Or when you click on a section it will say ?menu=tableName in the url. That's the name you want to copy. Change 'category' to the be the name of your table.

Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com