Page 1 of 1
PHP to create an Array Key for use in Chronoforms
Posted: Wed Jul 16, 2014 1:17 am
by irvinmetcalf
Hi.
I need PHP code to be able to loop through ALL records in a table [ j25_teamlist2014 ] and append these fields values [ Team, Day, Time, Lane, Status ] where the Status='Free' , and add them under a new array key called ('teamslots') then use the array key in the "Title" field in the "Dynamic data" settings of my Chronoform Version 4 dropdown box.
Any assistance would really be appreciated.
BR Irvin
Re: PHP to create an Array Key for use in Chronoforms
Posted: Wed Jul 16, 2014 5:39 am
by Celauran
OK, and where are you getting stuck?
Re: PHP to create an Array Key for use in Chronoforms
Posted: Wed Jul 16, 2014 7:01 am
by irvinmetcalf
Hi Celauran,
Right at the beginning I'm afraid. I have never studied PHP so an absolute novice. I've browsed around the forums but never found anything which matches what I need to do.
Its a dropdown box in Chronoforms for a website form which I need the PHP code for.
Here is the full story, hope you are able to help please:-
I want a dropdown box in my chloroform Version 4 on my Joomla 2.5 site to list the records which have a status of ‘Free’.
This is fairly easy to do, but is a bit meaningless as you get a list of items which all say free!
The table contains the following fields (which you may be familiar with)
I'm trying to get dynamic data from a data base ( j25_teamlist2014 ) into a dropdown box when the form loads.
This is the data in the data base:-
Team,Day, Time, Lane, Team Name, Team Captain, Status
001, Fri 07Feb14, 13:30, 1 GANF-Ambergate, Anita Asken
Confirmed
Etc.
I want to be able to load Team, Time, Lane and Status. But only those records where the status is "Free". The maximum free records is 280.
Chronoforms will only allow one of the fields to be in the dropdown box, which appears meaningless.
I have been advised as follows by the Chronoform help desk:-
#2- appending multiple fields values in the dropdown, this is more advanced, you will need a piece of PHP code to loop through ALL records and append these fields values, and add them under a new array key then use the array key in the "Title" field in the "Dynamic data" settings.
So the PHP needs to loop through the table, extract the records which are free and put the Team, Day, Time, Lane into an array called ‘teamslots’
Ie, the array row one may look something like ‘001_Fri6Feb14_07:30_1_Free’ representing team, day, time, lane, status. The array can then be referenced to the drop down box.
This PHP code would run from within the chronoform coding.
Does this fully explain?
BR Irvin
Re: PHP to create an Array Key for use in Chronoforms
Posted: Wed Jul 16, 2014 8:11 am
by Celauran
I'm neither familiar with Chronoform nor Joomla, but what you're describing sounds fairly straightforward.
Code: Select all
$query = "SELECT `team`, `time`, `lane`, `status` FROM j25_teamlist2014 WHERE `status` = 'free'";
$results = $db->query($query); // Pseudo code as I'm not familiar with Joomla's DBAL
foreach ($results as $result) {
// do stuff here
}
Unfortunately, that's about as specific as I can be without knowing what the form expects.
Re: PHP to create an Array Key for use in Chronoforms
Posted: Thu Jul 17, 2014 12:53 am
by irvinmetcalf
Thanks .
I'll play with this code and see if I can get it to work