A drop-down year list to display different categories books.

4 posts by 3 authors in: Forums > CMS Builder
Last Post: April 28, 2013   (RSS)

By gregThomas - April 19, 2013 - edited: April 19, 2013

Hi Jac,

Here is some example code of how I think you need to set up the drop down menu:

<form method="get" action="test.php" >
  < select name="category" id="jumpMenu">
    <option value="">Choose a year</option>
    <option value="2013">2013</option>
    <option value="2012">2012</option>
    <option value="2011">2011</option>
    <option value="2010">2010</option>
  </select>
  <input type="submit" name="go_button" id="go_button" value="Go" onclick="MM_jumpMenuGo('jumpMenu','parent',0)" />
</form>

This is just example code, you'll have to make a few changes to get it working.

So I've set the form up so that it uses the get method to send data so that the data will appear in the URL. I've changed the name of the select menu to category, you will need to use the name of the field that stores the book year. I've changed the values of the options so that they contain the year value. 

I also changed the input type of the button to submit. 

You'll also have to make sure you have allowSearch set to true in your getRecords function:

// load records
list($example, $exampleMetaData) = getRecords(array(
  'tableName'   => 'example',
  'where'       => '',
  'allowSearch' => true
));

It might also be worth looking into using the getListOptions function to retrieve your options from the section, you can read about it here:

http://www.interactivetools.com/forum/forum-posts.php?postNum=2230160#post2230160

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By esupport - April 28, 2013 - edited: April 28, 2013

Hi Gerg

I try many times.  I just confused how to get my database.

getListOptions('myTableName','myFieldName')  <------ Nice!

It wonderful now!

Share my code for reference :

<form method="get" action="birds_mag_list.php" >

   <?php $options = getListOptions('birds_mag_list', 'list'); ?>

     <select name="list">

       <option value="">&lt;select&gt;</option>

          <option value="">Any</option>

            <?php foreach($options as $value => $label): ?>

          <option value="<?php echo $value; ?>" ><?php echo $label; ?></option>

     <?php endforeach; ?>

    </select>

   <input type="submit" name="go_button" id="go_button" value="Go" onclick="MM_jumpMenuGo('jumpMenu','parent',0)" />

</form>

Thanks a lot!

Jac

-Jax H.

By Mikey - April 28, 2013

Have a look at this thread. I think it's exactly what you're looking for and it's a great solution for providing years in a drop down, because you do not have to hard code your options.

In response to: [url "https://www.interactivetools.com/forum/forum-posts.php?postNum=2207818#post2207818"]Re: [zick] Listing Records that have Multiple Category Options[/url], ...