...

View Full Version : manage record of bridge table



shajiuddin
01-11-2012, 03:06 PM
Hi,

I have 3 tables

1 Screens
2 Items
3 Screen_Items (Bridge table)

On page there's list of all 'Items' as 'check boxes' for particular 'Screen' and we should select multiple 'items' for that particular 'Screen'

Problem is:

How can I define the single/multiple Items (check boxes) are selected by user then store to 'Bridge Table'?

If I unchecked a checkbox then I have to delete that record from bridge table?

I am attaching txt file please help me

mlseim
01-11-2012, 07:12 PM
Can you describe what a "bridge table" is?

PHP handles checkboxes in a strange way compared to text boxes and other arrays.
When you process the form, the array of checkboxes will ONLY contain the checkboxes
that are checked. So, one time, the array will have 1 item in it, other times, it may
have 4 items. You only know which one's were checked.

You want to also know which one's are NOT checked.

Because you're already using a hidden array to contain all of the ID's, you've
given yourself a good way to deal with this ...

This is your hidden array I'm talking about ...
<input type="hidden" name="item_id[]" value="<?php echo $app_obj->id;?>" />

This is your checkbox array ...

<input <?php if (!(strcmp($rowm['item_id'],$app_obj->id))) {echo "checked=\"checked\"";} ?> value="<?php echo $app_obj->id;?>" type="checkbox"
name="item_<?php echo $rowm['id'];?>" />

Your checkbox name should be a constant, like "check_id[]" ...
So, when you process both arrays, item_id[] and check_id[],
you can compare them. The ones contained in both arrays must
be checked. The missing ones were not checked.

This is how to get the difference between both arrays ...
http://php.net/manual/en/function.array-diff.php

I'm just rambling here, not knowing what a "bridge table" is ...
Maybe I'm way off track? If so, sorry.


.

shajiuddin
01-12-2012, 06:37 AM
Hi,

Bridge table (screen_items) is that where 'screens' and 'items' ids are storing

There is One-Many relationship between 'screens' and 'items'. It means 1 'screen' can have many 'items' and 1 'item' can be in any 'screen'. That's why I created bridge table 'screen_items' which has 3 fields

1. id (PK) auto increment
2. screen_id (FK comes from screens table)
3. item_id (FK comes from items table)

At first there is a list of 'screens' with link 'Items'. If I click on 'Items link' for any 'screen' then I redirect to another page where all 'items' are showing where I can select 'item/items' for that selected 'screen'


Problem:
If I checked any 'item/items' for selected 'screen' then if selected 'item/items' already exist for selected 'screen' then record will remain same but if I unchecked 'item/items' for selected screen then record should be delete.

you understand my meaning... I need to do the process of adding/updating/deleting on the same page

Please check my txt file and if you can correct logic then please send me correct one or tell me better advice

Regards

shajiuddin
01-12-2012, 09:21 AM
yes as I already mentioned

'There is One-Many relationship between 'screens' and 'items'. It means 1 'screen' can have many 'items' and 1 'item' can be in any 'screen'. That's why I created bridge table 'screen_items' which has 3 fields'

1. id (PK) auto increment
2. screen_id (FK comes from screens table)
3. item_id (FK comes from items table)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum