How to Update Related Records if Checkbox is checked

Tessa

Member
Hello!

I have "table_foo" and "table_bar".
table_foo has many table_bar (one to many relationship).

Well, i have a copy of table_bar that has a checkbox that says "Update All?", so instead of updating the individual record, it will update all related records. Note that there is no JOIN because it will mess up editing the form the way it's set up.

I understand I need to add a custom PHP form script, do you have any examples of a related situation?


Here's the real situation:

I have table Model and table Sizes.

I have a copy of the Size table, and want to have an option to edit a record and include some data that is unique to all the sizes of the model, or if the "Update All" checkbox is unchecked, it would only update that size itself.

Looking forward to a response. :)

Tessa

Latest Joomla 2.5.x version
Updated from Github like 2 weeks ago
 
Update, looks like I have to join the 2 tables together although I mentioned I wasn't. Have to filter by elements from Parent table. lol
 
hi Tessa is this question still outstanding - or did the join resolve the issue?
-Rob
 
Hi Rob, strange I didn't receive a notification of your response. :p

I didn't find a solution yet. Any recommendations or resources?

Thanks!
 
I guess you would need a php form plugin on the Model form to get the data submitted and update the related records in the sizes table. so pseudo code:

PHP:
$app = JFactory::getApplication();
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$rowid =  $app->input->get('rowid');
$updateValue = $app->input->get('model_common_info');
$query->update('sizes')->set('common info = ' . $db->quote($updateValue)) ->where('sizes.model_id = ' . $db->quote($rowid));
$db->setQuery($query);
$db->query();
 
Thanks again for the help, but I'm not seeing how this would work if I selected a checkbox and if the checkbox is checked, then it should update all the related records (all sizes) to that model.

I can't wrap it with if (checkbox == "1") because there is no value assigned to it. It has to happen if checked and before form is submitted.

PHP still confuses me. You'd think I'd figure it out after this long LOL :)

Kindly awaiting a response. :)




I guess you would need a php form plugin on the Model form to get the data submitted and update the related records in the sizes table. so pseudo code:

PHP:
$app = JFactory::getApplication();
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$rowid =  $app->input->get('rowid');
$updateValue = $app->input->get('model_common_info');
$query->update('sizes')->set('common info = ' . $db->quote($updateValue)) ->where('sizes.model_id = ' . $db->quote($rowid));
$db->setQuery($query);
$db->query();
 
Great article Rob! I'm still a bit inexperienced when it comes to JS.

I tried to paste my code but it got wiped a few times, so I am using a pastebin type of site.

Is this any closer? The JS is messed up, but you see my idea? :-D

http://snipt.org/XBm8
 
Hi Tessa
Probably best to catch me on the chat to discuss this one ;) I'm online for the next 9 or so hours
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top