Form: updating data in a different table

uktran

Member
This isn't really a bug, and quite generic, so happy to pointed in the right direction....

I have two separate tables.

Table A
UserA, filenameA, infoA,

Table B
UserB, filenameB, infoB

Sometimes I want to copy the corresponding data from A to B.

Is it possible to update table B with the equivalent data when the form is edited/resubmitted. (or even better with an update column button)
 
I think I managed to do this with the upsert plug in.

Bonus points, if this is possible to do with the update column plugin also?
 
Can you explain a little more about your structure? I see two tables with the same setup so I need to understand why you have two tables.
 
I have one master table with two colunms, User and Job. By default user is blank. So for example I have a list of three jobs as follows:

Table_a
{User}, joba
{User}, jobb
{User}, jobc

The idea is that Users can submit applications for each job with one click , which are stored in a seperate table.

So for example, if 3 users press the button to signal interest in lota and 1 user is interested in lotb the second list might look like this:

Table_b
User1, joba
User2, joba
User3, joba
user4, jobb

So I am trying to use the php plugin in create a button which inserts a new row in a separate table to create a list of applications.

I have more columns than this, but if I can figure out this first step, I should be able to extrapolate.

The code below is successful in inserting a new row with the user ID, but I can't figure out how to insert the job variable into Table B

$user = & JFactory::getUser();
$user_id = $user->id;
$mm = $db->quoteName('Mins');
$ids = JRequest::getVar( 'ids', array(), 'method', 'array' );
$row = $model->getRow($ids[0]);
$db = FabrikWorker::getDbo(false, 1);
$db->setQuery("insert into table_b set User= " . $user_id);
$db->query();
 
I've made some progress. I can get the file ID and user ID. However, I can't work out how to get the actual variable data for the ID.

I think I can probably get to my goal using joins so no panic. But less urgently , it would be handy to know how to grab the actual variable data for the job title


$db =& JFactory::getDBO();
$ids = JRequest::getVar('ids', array());
$user = JFactory::getUser();
$userid = $user->get('id');
$count = 0;
foreach ($ids AS $id) {
$update = "insert into c_job (job, User) VALUES('$id','$userid')";
$db->setQuery($update);
$db->query();
$count++;
}
$msg = JText::_('Changed viewers to Everybody on ' . (int)$count . ' records.');
$params =& $this->getParams();
$params->set('table_php_msg', $msg);
 
You can try
Var_dump($data); exit;
To see if $ data contains what you need.
But I don't understand what you are doing. Do you know the database join element? You can use it e.g. with checkbox/ multiselect or in a repeated group

gesendet mit Tapatalk
 
Hi, it's tricky to describe. I'll use an analogy. I have a series of rows in table_a which I want users to be able to place a vote on.

This table has three columns, name of fruit, the price of the fruit, and a count the votes for that fruit.

Table_a
(fruit, price, vote count)
---------
apple , 10 , 0
pears, 15, 0

So I have a second table called votes_a which lists the votes. so a user clicks the PHP button next to apple and a row is added to votes_a

Votes_a
(user, fruit, price)
--------------------
User1, apple, 10

And table a updates to reflect a count of the records featuring apple.

Table_a
(fruit, price, vote count)
---------
apple , 10 , 1
pears, 15, 0


The reason I can't use a join, is that I need the user to be able to access and edit the price of the fruit, for their own record in the Votes_a table in a later form.
 
Back
Top