database query via php

Status
Not open for further replies.

uschmi

Member
In a form (=data from table1) I want to update several field values with data from table2 via php plugin.
F.ex.: table2___userid -> table1___userid, table2___surname -> table1___surname ...

I tried with no success:
PHP:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$meinUser = $formModel->formData['table1___userid'];
$query->select('*')->from('table2')->where('user = ' . $db->quote($meinUser));
$db->setQuery($query);
$ergebnis = $db->loadResult();
...

Could someone please help with an example, how to retrieve data from a db table and put them into the form fields?
 
In your query, you retreive (select) the data from table2.
If you want to update it (with the data from table 1), you need to do an update query.
I would write it for you but i don't know what condition you need to use for the "where" part. How do you choose which record to update in table2?
 
Thanks for your answer. Ok, let me try to explain:

table1 contains the employees of the company.
table2 contains documents related to the staff. There can be many documents related to one employee.
In both tables, there are a field "userid", which contains the id from jos_users.
When an employee creates a new document (record in table2), the personal data (surname, first name, birthday...) should be fetched from table1 and stored in the corresponding fields in table2.
To access the correct record in table1, table1___userid have to match with table2___userid...

Hopefully, this is not explained to complicated.

I?m using the newest fabrikar version from Github.
 
Have a look at the autofill form plugin. It should do this.

Do you really need a copy of this values in your 2nd table? Maybe you can use a dbjoin element with CONCAT surname,firstname...
 
Status
Not open for further replies.
Back
Top