CalcBuilder Forum

Linked List Questions

User moon_1869 2014-11-28 14:53:35

Hi,

I have some questions about the linked lists, I saw there are several options available:

1. Linked List with manual options
2. Linked list with sql options
3. Linked list (sql)

I have managed to get the lists depending to each other by first setting up the option list and the next group using the linked list. With the normal option list i use a variable name like group1 and the next two linked lists group1_linked1 and group1_linked1_linked2.

Now I got it managed working and all the options are changing and can get the ID name and value if using "static" options, if i connect it to the sql database I get this:

1st normal list (not sql):
var linkedvaltmp="";linkedvaltmp=new obj_LinkedValue("12","1_int","interior");

1st normal list (sql):
var linkedvaltmp="";linkedvaltmp=new obj_LinkedValue("1_int","1_int","interior");

Now my sql table has the following structure:

id, location, distance, name, nameabreviation, and value.

id is the normal id wich will autoincrement
location is a number that refers to another table and can be indoor or outdoor
distance is a name that will be used in the 2nd list depending on the 1st list
name is the name of the product
nameabreviation is the short name of the name of the product that i need to connect to the matrix
value is just a number that i use for calculating

How can i get the value inside the linkedvaltmp like:

var linkedvaltmp="";linkedvaltmp=new obj_LinkedValue("1_int_2nd","1_int_2nd","NAME")

to

var linkedvaltmp="";linkedvaltmp=new obj_LinkedValue("VALUE","1_int","NAME")

or

var linkedvaltmp="";linkedvaltmp=new obj_LinkedValue("NAMEABREVIATION","1_int_2nd","NAME")

What will be the query for sql? or do i need to add a js somewhere to control this?? It needs to connect to the matrix. The matrix rows uses the nameabreviation to indicate the values.

Edited by moon_1869 - 28.11.2014 14:54

Edited by moon_1869 - 28.11.2014 14:55

Edited by moon_1869 - 28.11.2014 14:56

Moonsoft support 2014-11-30 09:56:40

Hi,
when using options list linked (sql), you will build your options at the backend, and recover at the code, there will be no javascript involved, and you don't need to name your fields in any specific way, you can have
firstoption
secondoption
thirdoption
...
You can type the independent options as required(texts, options...), and you have to use the field type 'linked list (SQL)' for the dependant comboboxes. The linked list sql query supports to include values from other fields to filter the options, so you can configure it this way:


select id,name from #__users where name = ##fieldname##


for your case you can select your own columns

select id, name from ..... where anycolumn=##previousfield##


Where ##fieldname##, ##previousfield## can be any other field of your calculator. If you also select the field that will 'reload' the dependant field when changed you will get your option list refreshed with the values allowed.


Once you have the form ready, you will recover your values normally at the code

$firstoption
$secondoption
$thirdoption


if you need to access again your database to recover another column of the table for your calculations, then you can use more sql, this time at the code section. This is an example to get a column from db:

$db =JFactory::getDBO();
$query = "select another_column from #_mytable where id=".$myoption;
$db->setQuery($query);
$anothercolum=$db->loadResult();


//here you will have $anothercolumn ready to be used.


Hope this helps, regards

User moon_1869 2014-12-06 00:02:32

thank you very much, works like a charm... the only thing i couldnt solve is that i have several matrix lists with variable names like:

$matrixtable1
$matrixtable2

So when i call i do the following:

$db =JFactory::getDBO();
$query = "select another_column from #_mytable where id=".$matrixtablename;
$db->setQuery($query);
$matrixresult=$db->loadResult();

and then

$getmatrixvar=$matrixresult;

$horizontal comes from one of the results from the form...

But it gives me an answer "e"... How can i get the matrixlist variable dynamic so $matrixresult can be any of the matrix lists??

Moonsoft support 2014-12-08 09:17:02

Hi,
once you have recovered the 'name' of the matrix you want to access, you can use the $$ operator to use 'the variable named as', so you could try:

$getmatrixvar=$$matrixresult;


Hope this helps, regards

User moon_1869 2014-12-08 15:51:14

I tried it but it doesnt seem to work with the double $$. Is there another way??

Moonsoft support 2014-12-09 09:49:02

The $$ operator is the right way in PHP to get a 'real' variable based on its name. You can try this instead:

$myrealvar=$$matrixresult;
$getmatrixvar=$myrealvar;



Regards

User moon_1869 2014-12-09 19:07:01

Hey thanks, yes that did the trick... Also i found another mistake inside the calculations but case closed.

...
Support/development 40 hours

With the peace of mind of having a professional team at your service (20% discount)

Buy now!
...
List Manager

Build different lists for your site

Buy now!