ChronoEngine.com homepage

Forums

Please write a review for the extension you are using on the Joomla extensions directory before posting a new question as we are being spammed by many negative reviews.

Thank you for your support!

DROPDOWN dynamically feed

extrom 28 Jun, 2018
I am using chronoforms v6 and noticed that in many cases there is no need to create extra code for some functions.
I am counting the number of records in a database and hovering LOOP to generate a list for a DROPDOWN ...
Example: I find that I have 4 records in a database, how to dynamically feed a DROPDOWN with the "1,2,3,4" choice options?
Is there a way to implement without generating extra code?
healyhatman 28 Jun, 2018
There's a dynamic dropdown example in the demo forms.
extrom 28 Jun, 2018
I am using a PHP to populate the dropdown with a count of database records, one same works well plus I have to get the maximum value of records that comes from the amount of records in the database. The value is in read_data15 it indicates that it is number 3, however when using in "for" this value is ZERO ...

//return array("Ponto 1","Ponto 2","Ponto 3","Ponto 4",);
$results = array();
$quant = '{var:read_data15}';
$results[] = 'Selecione o ponto desejado';
for ($i = 1; $i <= $quant; $i++) {
$results[] = 'Ponto '.$i;
}
return $results;

how can I get around this problem?
extrom 28 Jun, 2018
//return array("Ponto 1","Ponto 2","Ponto 3","Ponto 4",);
$results = array();
$quant = '{var:read_data15}';
$results[] = 'Selecione o ponto desejado';
for ($i = 1; $i <= $quant; $i++) {
$results[] = 'Ponto '.$i;
}
return $results;
extrom 28 Jun, 2018
return '{var:read_data15}';

by simply testing with this I get the value 3 ...
extrom 28 Jun, 2018
Healyhatman...

thus ?

$results = array();
$quant = '{var:read_data15.model}';
$results[ ] = 'Selecione o ponto desejado';
for ($i = 1; $i <= $quant; $i++) {
$results[ ] = 'Ponto '.$i;
}
return $results;
healyhatman 28 Jun, 2018
m are you sure it's 3, or is it an array containing the number 3
extrom 28 Jun, 2018
I am counting records through the option below in read_data15 and currently have 3 records ... I need this value inside the "for" to be able to create 3 elements in the array that goes to the dropdown when returning from PHP

the read_data15...

Select type = Return the count of records matching the filtering conditions.
healyhatman 28 Jun, 2018
Oh sorry I see the problem. You can't use shortcode a in PHP.

{var:} should be $this->get("variable name", "default if not found");
extrom 28 Jun, 2018
any problem to overcome the problem?
healyhatman 29 Jun, 2018
I just told you? What is it you're asking?
extrom 29 Jun, 2018
Thanks, follow a link to video with the implementation.

https://youtu.be/mkr_460kmuM
healyhatman 29 Jun, 2018
$quant = $this->get("read_data15", 0);


You didn't read what I wrote properly, $this->get takes two parameters - the name of the variable you want to retrieve, and a default value if the variable is not found.
healyhatman 29 Jun, 2018
Also try doing

return json_encode($results);

and in the dropdown value put

{var/jsonde:php17}
extrom 29 Jun, 2018
Thanks a lot for the guidance, you are correct ... however the implementation described in the video is working correctly ... at the time I noticed that $ this in the chronoforms is an access to the entire structure of the project simply by knowing how to access the desired variables, thank you...

Throughout my code I will certainly have other doubts, thank you very much.
This topic is locked and no more replies can be posted.

2Checkout.com

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com