Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    69
    Thanks
    6
    Thanked 0 Times in 0 Posts

    manage record of bridge table

    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
    Attached Files Attached Files

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,509
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    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.


    .
    Last edited by mlseim; 01-11-2012 at 06:25 PM.

  • #3
    New Coder
    Join Date
    Sep 2011
    Posts
    69
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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

  • #4
    New Coder
    Join Date
    Sep 2011
    Posts
    69
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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)
    Last edited by shajiuddin; 01-12-2012 at 08:22 AM. Reason: more detail


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •