Forums

Dynamic dropdown based on a subset of a field

CyborgPrime 05 Dec, 2016
Hello-
I want to populate a dropdown from an external menu, but i want to run a WHERE on the query that populates the drop down.

i have the dropdown working- it displays ALL the entries for the field but I only want to display some of the field records.

For instance, let's say the field is a list of people's last names (l_name), and I only want to populate the dropdown with names="smith".. how do I do that? where do i put the code?

user_id, l_name
0,smith
1,jones
2,jackson
3,smith

In this example, I want to load just the names "smith" into my dropdown.

Thanks in advance!
GreyHead 05 Dec, 2016
Hi CyborgPrime,

You'd add an entry in the Conditions box of the DB Read action to limit the selection. There isn't enough info here to say exactly what that would look like though.

Bob
CyborgPrime 05 Dec, 2016
I want to just load it with l_name where l_name="smith".

Maybe this is a better example: I want to load l-name into the drop down where membership_renewal>=today.

I get that it goes in the conditions box, but not sure the syntax db read is expecting.

Thanks!
CyborgPrime 05 Dec, 2016
To make that clearer:

user_id, l_name, renewal_date
0, smith, 12-25-16
1, jones, 07-05-15
3, jackson, 12-15-16

I want the dropdown to load the names if the coresponding renewal date has not yet occurred, so the resulting drop down would only contain smith and jackson.

Thanks!
GreyHead 05 Dec, 2016
Answer
Hi CyborgPrime,

Please see this FAQ

The condition will be something like
<?php
return array(':model_id.renewal_date >= NOW() '); 
?>

Bob
CyborgPrime 05 Dec, 2016
I saw that FAQ before I posted here, but I didn't get what it was trying to say. You helped clarify that with your answer- thank you!

I didn't get what the examples were trying to show,but I WAS in the right area I guess, I was trying to figure out how to alter Complex Query for my purposes. But I get it now, thanks for your help!
CyborgPrime 05 Dec, 2016
Thank you!

I had a model on a db read called "upcoming_events" and I only wanted the dropdown to load with events that haven't happened yet.

So with your help, this is what I ended up with:

    <?php
    return array(':upcoming_events.event_start >= NOW() '); 
    ?>


This worked! What a great program Chronoforms is.. Thanks again!
This topic is locked and no more replies can be posted.