Forums

Reading specific Record from Database

viperius 24 Jan, 2015
Hi there,

I am fairly new to Cronoforms and I am trying to setup my first form.
User logs into Joomla and I want to then give them the option to edit some data which is in a custom table which is tied to their account.

The id they have from the Joomla users table and the id for their record in the custom table are the same.

I have setup a form and if I set the option to read the DB it gives me the first record, which proves that it is reading the table.

What and where do I have to put stuff to get it to read the record for the logged in user.

Thanks in anticipation

Kenny
Max_admin 24 Jan, 2015
Hi Kenny,

If you have v5 then in the "conditions" box:

<?php
$user = JFactory::getUser();
return array("user_id_field" => $user->get("id"));


Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
GreyHead 24 Jan, 2015
Hi Kenny,

Please see this FAQ. The same code will work in CFv5. And this FAQ for the WHERE clause.

Bob
viperius 24 Jan, 2015
ok thanks for that...I am now one step closer. I switched debug on so I can see what is happening.

I can now retrieve the data based on the logged on user but it is not populating into the form.

Sorry to be a pain but once I get the hang of this hopefully I will be off and running

Kenny
GreyHead 24 Jan, 2015
Hi Kenny,

+ The DB Load action needs to be before the HTML (Render Form) action.
+ The column names of the DB Record need to match the input names in the form (including any Model ID you use) or you need to use a Custom Code action to map them across.

Bob
viperius 24 Jan, 2015
I have the DB Read first and I have switched on Debug and I can see the details in the array.

If I only have it pick up the first record in the simple DB Read I get the first record and it puts it in the form.

Could it be the fact that I have things an array that I am not addressing the data items properly

This is what I get from the debug screen

Array
(
    [option] => com_chronoforms5
    [chronoform] => ApplicationForm
    [0] => Array
        (
            [id] => 342
            [username] => xxxxxxxxxx
            [app_experience] => Experience Details in Here
            [app_bringtoclan] => I bring stuff to the Clan
            [app_weakpoint] => My Weak points go in here
            [app_timezone] => TZ
            [app_other] => Other comments go in here
        )

)


On my input form I have my Field Name and field ID set to for example app_experience etc

like I say it works if I only take the first record...
Max_admin 25 Jan, 2015
Answer
Please change the "DB Read" setting "Multi read" to "No"

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
viperius 25 Jan, 2015
Awesome....its simple when you know how.
mic77 07 Feb, 2015
good morning

I have the same problem,

I have put the "multi read" to "no" and he read me the first user of the database, not the connected user :?

(sorry for my english but I'm french)
Max_admin 08 Feb, 2015
Hi Mic77,

In order to get the connected user you must use the "Conditions" box:

<?php
$user = JFactory::getUser();
return array("id" => $user->get("id"));


Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
mic77 08 Feb, 2015
when I put this code, I display:

Si les difficultés persistent, merci de contacter l'administrateur de ce site.

1054 Unknown column 'Data.user_id_field' in 'where clause' SQL=SELECT `Data`.`id` AS `Data.id`, `Data`.`uniq_id` AS `Data.uniq_id`, `Data`.`user_id` AS `Data.user_id`, `Data`.`created` AS `Data.created`, `Data`.`modified` AS `Data.modified`, `Data`.`imprimee` AS `Data.imprimee`, `Data`.`nom` AS `Data.nom`, `Data`.`prenom` AS `Data.prenom`, `Data`.`rue` AS `Data.rue`, `Data`.`ville` AS `Data.ville`, `Data`.`sanguin` AS `Data.sanguin`, `Data`.`donneur` AS `Data.donneur`, `Data`.`maladie` AS `Data.maladie`, `Data`.`allergie` AS `Data.allergie`, `Data`.`medecin` AS `Data.medecin`, `Data`.`notaire` AS `Data.notaire`, `Data`.`convention` AS `Data.convention`, `Data`.`personne1` AS `Data.personne1`, `Data`.`personne2` AS `Data.personne2`, `Data`.`checkbox23` AS `Data.checkbox23`, `Data`.`button17` AS `Data.button17` FROM `lf5g6_chronoengine_chronoforms_datatable_carte` AS `Data` WHERE `Data`.`user_id_field` = '505'
Max_admin 09 Feb, 2015
The field name is "user_id", but not "user_id_field"

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
mic77 09 Feb, 2015
Thank you, that's right 🙂

I also like that it does not register a new row in my database,
but update, what code in my DB Save?
GreyHead 09 Feb, 2015
Hi mic77,

In this line replace the first 'id' with the name of the database column where you have the user ID - it looks as though that is user_id.
return array("id" => $user->get("id"));
Simplifying a bit you get:
return array("user_id" => $user->id);

Bob
Max_admin 09 Feb, 2015
for updating the record, use the same code in the "db save" action in the "update conditions" box!
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
This topic is locked and no more replies can be posted.