Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Joomla Form field type sql="....WHERE condition"?

In Joomla 2.5, how can I do a form field type "SQL" with the condition "WHERE" in the SQL query?

Example:

<field name="catid" type="sql" query="SELECT id, title FROM #__table WHERE {condition}" />

There isn't anything about this in the joomla docs. I've found this link but it doesn't refer anything of using a WHERE condition in the SQL query ( http://docs.joomla.org/SQL_form_field_type).

Can someone please tell me if this is possible or not to do in Joomla?

I have a table with products and a table with shops associated to brands. If I edit one shop I would like to show a combobox with all the products from the brand of the shop. Is that possible? SELECT * FROM #__products WHERE brand = {the brand id associated to the shop I selected for edit} Is this possible?

I was able to do this with a custom form field =)

http://docs.joomla.org/Creating_a_custom_form_field_type

Thank you RHR for your answer !

like image 328
Snitram200 Avatar asked Aug 29 '26 09:08

Snitram200


1 Answers

Here's my solution:

You can replace the query completely by doing the following:

1)Define you query:

$query = 'SELECT * from table_name WHERE table_id = '.$your_value;

2)Update your form field attribute:

$this->form->setFieldAttribute('field_name', 'query', $query);
like image 175
Jalil Avatar answered Sep 01 '26 04:09

Jalil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!