Skip to main content
Topic: Field datasource with conditional (Read 2620 times) previous topic - next topic

Field datasource with conditional

We know that for simple structures like country/province/city where each of the children can only belong to a parent, we can link multiple select fieldss using the field datasource  (OptionListDatasource) in Add/Edit pages. And it works really well, allowing to link several select fields to display only the values that belong to the previously selected parent.

But.. would it be possible to have a slightly more complex selection. This is the scenario.

* Country table
id, countryname
* Seller table
id, sellername
* Brand
id, brandname, idseller, idcountry
* Product
id, productname, idseller, idbrand, idcountry (and whatever else you want to add after)

So the intention is to be able to create a page to ADD products and follow this logic using select fields.

1. Select the Country
2. Select the Seller
3. Select the Brand (displaying only the brands matching the previous to selections for idseller and idcountry)

Things get complicated when a seller can sell in more than one country, and when a seller can sell the same brand in more than one country.

My goal is to figure if something like this is doable with current PHPRad tools, maybe with query parms, as I see something like this $lookup_country is added to query params in the case of simple scenarios. Would be possible to add 2 and make the query more complex?

 

Re: Field datasource with conditional

Reply #1
Hi, Do you have any solution for this :
My goal is to figure if something like this is doable with current PHPRad tools, maybe with query parms, as I see something like this $lookup_country is added to query params in the case of simple scenarios. Would be possible to add 2 and make the query more complex

Re: Field datasource with conditional

Reply #2
Complex select with the option field  might not be possible for the moment. But you can use the "Edit query button" to ediy sql query.

Re: Field datasource with conditional

Reply #3
This is a good exercise. Are all brands available in each country ?

Re: Field datasource with conditional

Reply #4
but, how i can build a query  where clause with two fields values

Re: Field datasource with conditional

Reply #5
@jfgonzalez
You can have a query like this
"SELECT COUNT(*) AS num FROM contact where name = ? OR name = ?" 
and query params
'Williams Akor','John Smith'

or

"SELECT COUNT(*) AS num FROM contact where name = ? AND name = ? AND name = ?" 
and query params
'Williams Akor','John Smith','John Doe'

The important thing is, no matter how complex your query is, remember to add the correct number of values or variables to bind to the query separated by comas.