how do I create a self populating filter list

7 posts by 2 authors in: Forums > CMS Builder
Last Post: July 3, 2014   (RSS)

By willydoit - June 30, 2014

Hi all,

I have just created a table for local authors and their books, I have created a list page that will list every book in the table, as some authors have more than one book available I would like to be able to allow the viewer to filter the list by author if they wish so that the list just shows all the books available from their selected author.

What I would like to do is to have the drop down author list self populate from the table, is there a simple way to do this, I am sure there should be but I am not a coder so am a bit lost on this.

the table is called "literary_corner" and the field which contains the authors name is "author_name"

Any help anyone can provide with this would be gratefully received.

Thanks in advance

By mizrahi - July 1, 2014 - edited: July 1, 2014

<?php
  // load records from 'literary_corner'
  list($literary_corner_dropdown, $literary_corner_dropdownMetaData) = getRecords(array(
    'tableName'   => 'literary_corner',
    'loadUploads' => false,
    'allowSearch' => false,
  ));
?>

<form action="./" action="get">
  <select name="author_name">
    <?php foreach ($literary_corner_dropdown as $record): ?>
      <option value="<?php echo urlencode($record['author_name']) ?>">
        <?php echo htmlencode($record['author_name']) ?>
      </option>
    <?php endforeach ?>
  </select>
  <button type="button">Submit</button>
</form>

By mizrahi - July 1, 2014

Can you post your full page code?

By willydoit - July 1, 2014

Due to the time difference i am not in the office at the moment, i will post the page for you tomorrow if thats okay.

steve

By willydoit - July 2, 2014

Hi,

Here is my current listing file. hope it helps. In case it is relevant all my cmsb listing and detail pages are in a subdirectory off the route folder called listings.

Attachments:

literary_list.php 30K

By willydoit - July 3, 2014

As an update to this I have re-thought how the section is constructed and have now been able to produce a working filter.

Thanks for your help.