Forums

Displaying table results based on Form data

jkrah 12 Apr, 2015
I hope someone is willing to help me.
I have build a simple form with two fields. Year and Event ('Jaar' and 'Evenement' in Dutch).
When the Year is selected, a dynamic dropdown populates the Event field. This wors fine.
You can find it here http://bvdp.krah.nl/index.php?option=com_chronoforms5&chronoform=Achmea

After submit I want to display the results from a table that I build in the Joomla db,

I tried Db Read Action (in the 'on submit' event, but I lack the knowledge on how to set that up properly.
I also tried in stead of the DB read a custom code action that displays the result from the table based on the selections made in the form, but the query is not picking up my {year} and {event} in the query:
I use this:
$result = mysqli_query($con,"SELECT * FROM bap_zk_achmea_uitslagen WHERE Jaar='{Jaar}' AND Evenement='{Evenement}' "); 

This gives the desired result:
$result = mysqli_query($con,"SELECT * FROM bap_zk_achmea_uitslagen WHERE Jaar='2013' AND Evenement='10 KM' ");


But the one with the variables does not seem to pick it up..
I am not a hero in PHP and searched the forum for hours for a solution but cannot find it.
I am sure it should be relatively easy, but I am running into a brick wall here.
Any suggestions/help are welcome.
jkrah 12 Apr, 2015
That is the other way round. I know how to save form data to a table and the second option is not what I am looking for
GreyHead 12 Apr, 2015
Answer
1 Likes
Hi jkrah,

You can't use the curly brackets syntax {Jaar} in PHP, Instead use $form->data['Jaar'] e.g.
" . . .WHERE `Jaar` = '{$form->data['Jaar']}' AND `Evenement`  = '{$form->data['Evenement']}'
which uses the different PHP curly brackets.

To use the DB Read action set the Table to point to your table and add a WHERE clause in the Conditions box like this
<?php
return array('Jaar'  => $form->data['Jaar'], 'Evenement'  => $form->data['Evenement']);
?>
See this FAQ for more examples.

Bob
jkrah 12 Apr, 2015
ah, you are amazing, Thanks it works!
This topic is locked and no more replies can be posted.