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 willydoit - July 1, 2014

Hi Mizrahi,

Thanks for that, it is appreciated, I took your code and placed the first part before the head section of my php page and the form part in the body, I got a code error  which looks as though it was related to <form action="./" action="get">  I wasnt't sure if I was supposed to change whatever was between the " "  but looked at a similar type of form and replaced the form action line with  <form method="post" action="literary_list.php"> which I assumed would just post the search results back to the same page. This got rid of the error however although the drop down list populates and I can select different authors nothing happens when I hit the submit button, the page doesn't refresh and the content doesnt change. I am obviously missing something here but cannot understand what.

I have checked the variable names and they seem fine so am at a loss to understand why it doesn't work I assume it may have something to do with the form action element but need some help to understand what. It seems as though the page doesn't understand what it should be doing when the submit button is pressed if that makes sense.

Thanks again for your help.

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.