PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 14th, 2013, 02:10 PM
ran_dizolph's Avatar
ran_dizolph ran_dizolph is offline
from the lab...
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2004
Location: the land of wind and ghosts
Posts: 1,841 ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 37 m 13 sec
Reputation Power: 559
Checkbox processing for subscriptions

Hey folks,

I'm developing a system that basically allows users to 'subscribe' for various 'divisions' (of which there are around 15).

These are managed via checkboxes through their account, that they can update whenever they feel like.

My question is, is there an efficient way to process their division subscription changes?

There's the 'divisions' table, and a table joining the user to each division via user_id and division_id.

I just don't think that each time the user changes a division there should be a query to cross reference whether they are or are not subscribed, and updating the table based on their checkbox selections (or de-selections) relative to whether they are or are not subscribed already, but I can't really think of how else to handle it.

Any help'd be greatly appreciated!

Reply With Quote
  #2  
Old February 14th, 2013, 02:19 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,880 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 2 Days 8 h 3 m 52 sec
Reputation Power: 581
What difference does it make to the update whether or not they are already subscribed? Just update the all current selections without regard to previous selections.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #3  
Old February 14th, 2013, 02:24 PM
ran_dizolph's Avatar
ran_dizolph ran_dizolph is offline
from the lab...
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2004
Location: the land of wind and ghosts
Posts: 1,841 ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 37 m 13 sec
Reputation Power: 559
Quote:
Originally Posted by gw1500se
What difference does it make to the update whether or not they are already subscribed? Just update the all current selections without regard to previous selections.


Hmm, I suppose just for adding more subscriptions it wouldn't matter, but if they want to unsubscribe by de-checking a box, that's where it gets a little confusing/resource intensive, at least in my mind.

Thanks!

Reply With Quote
  #4  
Old February 14th, 2013, 02:35 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,880 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 2 Days 8 h 3 m 52 sec
Reputation Power: 581
From a database update perspective it doesn't matter. If you have to take other actions to unsubscribe someone then you would indeed need to check if they are already subscribed but I see no way around that. However, you only need to do 1 query to get the status of all the subscriptions so I don't see any problem with extra overhead from a database standpoint.

Reply With Quote
  #5  
Old February 14th, 2013, 03:34 PM
ran_dizolph's Avatar
ran_dizolph ran_dizolph is offline
from the lab...
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2004
Location: the land of wind and ghosts
Posts: 1,841 ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 37 m 13 sec
Reputation Power: 559
Yeah, I guess if I just put more work into processing/preparing the actual checkbox part of it, the mysql becomes simpler.

Was also thinking of maybe javascript/ajax to just do the work as they check/uncheck each box, rather than submitting the whole form.

Reply With Quote
  #6  
Old February 15th, 2013, 06:51 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,880 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 2 Days 8 h 3 m 52 sec
Reputation Power: 581
I think that would be less efficient as it means more DB transactions. However, unless you are expecting hundreds of transactions per minute I doubt any of your concerns will be worth a lot of effort.

Reply With Quote
  #7  
Old February 15th, 2013, 10:42 AM
ran_dizolph's Avatar
ran_dizolph ran_dizolph is offline
from the lab...
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2004
Location: the land of wind and ghosts
Posts: 1,841 ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 37 m 13 sec
Reputation Power: 559
Thanks for the input thus far. I think I've got a way to do this without javascript, but I'm just a bit unsure of the syntax.

Here's what I'm using for each form field (a common method i've found for processing checked, as well as unchecked form fields):
Code:
<label>Concrete:</label>
<input type="hidden" name="checkbox-5[]" value="0">
<input type="checkbox" name="checkbox-5[]" class="checkbox" value="1" >


The number after the hyphen is the unique ID associated with the division, which is what I actually need to use to either insert OR delete from the db.

Here's what I'm trying to use to either add or delete the division, but it's not working:
PHP Code:
if(isset($_POST['updateDivisions'])) {

    
$checkbox $_POST['checkbox'];
    
$countCheck count($_POST['checkbox']);

    for(
$i=0;$i<$countCheck;$i++) {

        
$div_id explode("-"$checkbox) ;
        
$div_id $checkbox[1][$i];

        if(
$checkbox[$i] == 1) {
        
        
$div_insert "
        INSERT INTO
            user_divisions
            (user, division)
        VALUES
            (
            "
.mysql_real_escape_string($_SESSION['user']['user_id'])."
            ,
            "
.mysql_real_escape_string($div_id)."
            )
        "
;
        
$div_result mysql_query($div_insert);
        
/*    
        } else {
            mysql_query("DELETE FROM user_divisions WHERE user = ".mysql_real_escape_string($_SESSION['user']['user_id'])." AND division = ".mysql_real_escape_string($_POST['checkbox'][$i])."") or die() ;
        }
        */
        
}
    }
}

// SUCCESS OR FAILURE MESSAGE WILL APPEAR ONCE THIS IS SORTED 


Any thoughts?

Reply With Quote
  #8  
Old February 15th, 2013, 11:08 AM
ran_dizolph's Avatar
ran_dizolph ran_dizolph is offline
from the lab...
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2004
Location: the land of wind and ghosts
Posts: 1,841 ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 37 m 13 sec
Reputation Power: 559
Okay, I got this sorted. I was overthinking how to do this.
I ditched the hidden field, and processed it with this:
PHP Code:
if(isset($_POST['updateDivisions'])) {

    
$total_divisions countDivisions() ;

    for(
$i=1;$i<=$total_divisions;$i++) {

        if (isset(
$_POST['checkbox-'.$i.''])) {
            
// ADD THE ENTRY
            
mysql_query("INSERT INTO user_divisions (user, division) VALUES (".mysql_real_escape_string($_SESSION['user']['user_id']).", ".$i.")") or die();
        } else {
            
// DELETE THE ENTRY    
            
mysql_query("DELETE FROM user_divisions WHERE user = ".mysql_real_escape_string($_SESSION['user']['user_id'])." AND division = ".$i."") or die();        
        }

    }  
    



It'll be cleaned up and return messages based on additions/deletions, but it works.

Thanks for the help thus far!

Reply With Quote
  #9  
Old February 15th, 2013, 11:11 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,880 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 2 Days 8 h 3 m 52 sec
Reputation Power: 581
Now all you have to do is rewrite the database statements to eliminate the deprecated MySQL extensions and use PDO.

Reply With Quote
  #10  
Old February 15th, 2013, 02:46 PM
ran_dizolph's Avatar
ran_dizolph ran_dizolph is offline
from the lab...
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2004
Location: the land of wind and ghosts
Posts: 1,841 ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level)ran_dizolph User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 37 m 13 sec
Reputation Power: 559
Quote:
Originally Posted by gw1500se
Now all you have to do is rewrite the database statements to eliminate the deprecated MySQL extensions and use PDO.


Had a couple of stabs at PDO on smaller projects, but that's for another day.

Thanks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Checkbox processing for subscriptions

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap