Forums

Display a list of records from database

pat01 26 Oct, 2018
Hi

I use the read_data to get the records form a database table.

If I set "First matching record" then the record is displayed. In the Design Tab I use:
{var:read_data3.EB_EVENTS.title}

This works fine!


But if I set "All matching records" (please see picture) no data is displayed. The code I use:
foreach ($form->data['read_data3.EB_EVENTS'] as $test) { echo "$test[title]<br>"; }

The debugger shows me that all records with location_id = 3 are loadet. So the data is there, but does not get displayed.

What is the correct code to display all records as a list including pagination (as set up in the Setup Tab)?

Thanks a lot!

Patrick
healyhatman 26 Oct, 2018
$this->get("read_data3.EB_EVENTS", "")

Should also probably look at the demo connections
pat01 26 Oct, 2018
Hi and thanks.

Unfortunately it's not working.

And I did check the demo forms, but there is none containing a data read and display multi records. (?)
pat01 26 Oct, 2018
Nothing. No data at all is displayed.
foreach ($this->get("read_data3.EB_EVENTS", "") as $test) { echo "$test[title]<br>"; }
healyhatman 26 Oct, 2018
Put a {debug:} at the end of your event
pat01 26 Oct, 2018
Please note: I have switched to the user table and renamed the model name to JO_USERS. Because the data of EB_EVENTS is not meant to be in public.

I now want to display the register Date of all registered users:
foreach ($this->get("read_data3.JO_USERS", "") as $test) {echo "$test[registerDate]<br>";}

Array
(
    [option] => com_chronoforms6
    [view] => form
    [Itemid] => 256
    [2b4002c33f6ef4fd61c68667aa7ef666] => mebtebroo6rg80tfj254qc4qn0
    [5d4522ec1447dd33418ee74075e1d6f8] => ucc81tgkehi52ia9j3u41mk6h1
)
Array
(
    [read_data3] => Array
        (
            [log] => Array
                (
                    [0] => SELECT COUNT(`JO_USERS`.`id`) AS `JO_USERS.count` FROM `k8d4f_users` AS `JO_USERS`;
                    [1] => SELECT `JO_USERS`.`id` AS `JO_USERS.id`, `JO_USERS`.`name` AS `JO_USERS.name`, `JO_USERS`.`username` AS `JO_USERS.username`, `JO_USERS`.`email` AS `JO_USERS.email`, `JO_USERS`.`password` AS `JO_USERS.password`, `JO_USERS`.`block` AS `JO_USERS.block`, `JO_USERS`.`sendEmail` AS `JO_USERS.sendEmail`, `JO_USERS`.`registerDate` AS `JO_USERS.registerDate`, `JO_USERS`.`lastvisitDate` AS `JO_USERS.lastvisitDate`, `JO_USERS`.`activation` AS `JO_USERS.activation`, `JO_USERS`.`params` AS `JO_USERS.params`, `JO_USERS`.`lastResetTime` AS `JO_USERS.lastResetTime`, `JO_USERS`.`resetCount` AS `JO_USERS.resetCount`, `JO_USERS`.`otpKey` AS `JO_USERS.otpKey`, `JO_USERS`.`otep` AS `JO_USERS.otep`, `JO_USERS`.`requireReset` AS `JO_USERS.requireReset` FROM `k8d4f_users` AS `JO_USERS` LIMIT 50;
                )

            [var] => Array
                (
                    [0] => Array
                        (
                            [JO_USERS] => Array
                                (
                                    [id] => 819
                                    [name] => Super User
                                    [username] => admin
                                    [email] => admin@domain.dd
                                    [password] => $2y$10$nnGhHvdFBZPN2sa7zKz1n.uOf1fZFn4sjQxhZadkBZPxRWyJ.ptcC
                                    [block] => 0
                                    [sendEmail] => 1
                                    [registerDate] => 2018-06-06 06:16:30
                                    [lastvisitDate] => 2018-10-26 09:44:37
                                    [activation] => 0
                                    [params] => {}
                                    [lastResetTime] => 0000-00-00 00:00:00
                                    [resetCount] => 0
                                    [otpKey] => 
                                    [otep] => 
                                    [requireReset] => 0
                                )

                        )

                    [1] => Array
                        (
                            [JO_USERS] => Array
                                (
                                    [id] => 820
                                    [name] => test zt
                                    [username] => test
                                    [email] => bhjhj@dssd.dd
                                    [password] => $2y$10$9YOPa97fl9oBY/tqn3ichu0EK6CYced3ix/9vWou9VnD2a/lgFlxq
                                    [block] => 0
                                    [sendEmail] => 0
                                    [registerDate] => 2018-08-03 13:44:19
                                    [lastvisitDate] => 2018-09-17 06:44:03
                                    [activation] => 
                                    [params] => {"admin_style":"","admin_language":"","language":"","editor":"","helpsite":"","timezone":""}
                                    [lastResetTime] => 0000-00-00 00:00:00
                                    [resetCount] => 0
                                    [otpKey] => 
                                    [otep] => 
                                    [requireReset] => 0
                                )

                        )

                    [2] => Array
                        (
                            [JO_USERS] => Array
                                (
                                    [id] => 821
                                    [name] => giuiug iuguigiu
                                    [username] => fffggiugig
                                    [email] => dfd@dd.dd
                                    [password] => $2y$10$xq7469ZCcCsONKnYm65LuuTdmxeIMzHMC5uDhd9PYWWPbeLCwrQXa
                                    [block] => 0
                                    [sendEmail] => 0
                                    [registerDate] => 2018-08-20 13:10:05
                                    [lastvisitDate] => 0000-00-00 00:00:00
                                    [activation] => 
                                    [params] => {"admin_style":"","admin_language":"","language":"","editor":"","helpsite":"","timezone":""}
                                    [lastResetTime] => 0000-00-00 00:00:00
                                    [resetCount] => 0
                                    [otpKey] => 
                                    [otep] => 
                                    [requireReset] => 0
                                )

                        )

                    [3] => Array
                        (
                            [JO_USERS] => Array
                                (
                                    [id] => 822
                                    [name] => fdfddf dfdf
                                    [username] => dffd
                                    [email] => dfdf2@sd.d
                                    [password] => $2y$10$JbDSugbAlSumQBircbjZNezw/OKsqwX7ubc0V/zdMba/1BLAEKyIO
                                    [block] => 0
                                    [sendEmail] => 0
                                    [registerDate] => 2018-08-20 13:10:35
                                    [lastvisitDate] => 0000-00-00 00:00:00
                                    [activation] => 
                                    [params] => {"admin_style":"","admin_language":"","language":"","editor":"","helpsite":"","timezone":""}
                                    [lastResetTime] => 0000-00-00 00:00:00
                                    [resetCount] => 0
                                    [otpKey] => 
                                    [otep] => 
                                    [requireReset] => 0
                                )

                        )

                )

        )

)




In frontend no data is displayed.
healyhatman 26 Oct, 2018
Answer
1 Likes
Sorry should be

for each ($this->get("read_data3", "") as $row) {
echo $row["model"]["field];
}

My bad
pat01 26 Oct, 2018
Great, thank you! Works!

And here the code if others want to use it:
<?php

foreach ($this->get("read_data3", "") as $row) {
echo $row['JO_USERS']['registerDate'] ."<br />";
}

?>
healyhatman 26 Oct, 2018
Why though when you can just use a table view
driv 28 Oct, 2018
Hi,
Is 'table view' available in ChronoForms?
This topic is locked and no more replies can be posted.