332 Posts
Kenneth
6 years ago
Topic

Hi.

I have used SQL Query field, along with live value of processing->SQL query to fetch a specific value from a table. This value shows when creating a new content item, but not when I edit.

The storage of the SQL query field is set to none, as it is just to read a value from DB when creating/editing a content item.

I use this value to show/hide fields in the site form, so it's just perfect that it shows up when creating a new item - but I still need this value to show the right fields when editing a item.

What I'm trying to do is to set a site wide variable in another content type. This item is always stored in the db with the same ID. Therefor all I need is to fetch and use the same value each time:

SELECT value_to_fetch AS value FROM #__table_to_fetch_from WHERE id=1 

This works on creating new, but not edit?

Get a VIP membership
4229 Posts
Kadministrator
6 years ago
5
Level 1

All live values only work on new item an not on edit.

332 Posts
Kenneth
6 years ago
0
Level 2

Is there I way I can go about getting a solution like this to work anyways?

4229 Posts
Kadministrator
6 years ago
3
Level 2

But there is also SQL field in the pack so you should rather use that one instead of live value sql field https://www.seblod.com/resources/extensions/plug-ins/sql-pack

332 Posts
Kenneth
6 years ago
2
Level 3

I tried using that without live query as well, but I only got the value when using the same string in process -> sql as live value on new item.

Perhaps the syntax is wrong:

SELECT style_variable AS value FROM #__cck_table WHERE id=1 

Do I have to place something in the default value area of the field perhaps? (I've seen the use of #value# etc in various forum post related to other solutions, but no luck)

EDIT:

Also I read on the link you gave: "It is manly usable to display some value in either content/blog view of Form&Content type or list/item view of Search&List type. On the form or search form it will display as ordinary text field and query won't be executed."

This means it will not work on form view? That's where I'm trying to fetch the value to.

1283 Posts
Bucklash
6 years ago
1
Level 4

What about before render field to do db query and then assign value to field

ie $fields['field_to_assign_value_to']->value = $resultFromDbQuery

and maybe:

ie $fields['field_to_assign_value_to']->form = "<input>".$resultFromDbQuery.</input>" <-not this but you kniw what I mean ... the entire field with value assigned....

332 Posts
Kenneth
6 years ago
0
Level 5

That could work. I'm not quite sure on how to use the correct code, and I've not used before render field before, so I would appreciate a bit of help to try this suggestion. 

On #__cck_store_form_footer I have one line with ID 77, and there is a field in the table named subitems_stil where I want to fetch the value.

In the site form I have a field named underside_stil which is the field I try to push the value into. This field sits in another content type and uses the #__cck_store_form_innhold table.

332 Posts
Kenneth
6 years ago
0
Level 1

I managed to find a solution for this. Using SQL pack and setting a restriction with SQL Query on the site form fields I want to hide.

Since I only have one row in the table I'm checking, the following line is sufficient (but it should be more specific according to number of rows etc in other tables):

SELECT * FROM #__cck_store_form_footer WHERE subitems_stil LIKE 'stil2'

Whenever column subitems_stil is set to stil2 this statement returns a result / is true and I can show the fields accompanying stil2 in my site form. Whenever I change subitems_stil to something else, the stil2 related fields in my site from is not shown. This holds true for new creation of content as well as editing existing. 

Get a VIP membership