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.
Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,346
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Quote Originally Posted by DjDanHayden View Post
    The values that are already set to 1 are the ones i had to set myself in the databse, when i try do it via the checkboxs it dosent update ?
    If the value in the database is already the same as the value your sql is trying to set it to, mysql will not make any changes and will not count it as an updated row.

    EG:
    id...... username
    1.......mike
    2.......john

    update users set `username` = 'john' where id = 2

    This would return 0 rows updated because that record already holds a value with john. Therefore mysql will not bother updating (thus saving the hard drive a disk write operation contributing towards its failure) and will consequently tell you it has updated 0 rows in its reply.

    I *THINK* thats what youre trying to describe.. if I've just answered a non-problem then youmight be better re-wording it.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  2. #17
    New Coder DjDanHayden's Avatar
    Join Date
    Nov 2008
    Location
    Ireland
    Posts
    55
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    If the value in the database is already the same as the value your sql is trying to set it to, mysql will not make any changes and will not count it as an updated row.

    EG:
    id...... username
    1.......mike
    2.......john

    update users set `username` = 'john' where id = 2

    This would return 0 rows updated because that record already holds a value with john. Therefore mysql will not bother updating (thus saving the hard drive a disk write operation contributing towards its failure) and will consequently tell you it has updated 0 rows in its reply.

    I *THINK* thats what youre trying to describe.. if I've just answered a non-problem then youmight be better re-wording it.

    Yes but i only want it to updates the values for the box's that are checked, the changed ones, from 0 to 1 (checked) or else from 1 to 0 (unchecked)


    Here is what i have:



    When i submit the form i want the checked boxs to set to 1 in the database.

  3. #18
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,346
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Quote Originally Posted by DjDanHayden View Post
    the changed ones, from 0 to 1 (checked) or else from 1 to 0 (unchecked)
    Ah I think I see what you mean now!

    What I think you mean is that you want them set to one if they are checked and otherwise set to 0.

    The problem is that checkboxes are only sent by the browser to php if they are checked so there is no way so submit an empty check box.

    You have two options:
    1) Update all the fields to 0 and then update the selected ones to 1 afterwards (2 queries but possibly better than the next idea)
    2) Change the form input to something else like radio buttons that will submit both true and false selections and then run either a large query if you can or multiple queries in a loop.

    There is no way to know in php that a check box is not checked unless you store them / their id in a session before printing out the page and then compare what is submitted back from that form against this list.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  4. #19
    New Coder DjDanHayden's Avatar
    Join Date
    Nov 2008
    Location
    Ireland
    Posts
    55
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    Ah I think I see what you mean now!

    What I think you mean is that you want them set to one if they are checked and otherwise set to 0.

    The problem is that checkboxes are only sent by the browser to php if they are checked so there is no way so submit an empty check box.

    You have two options:
    1) Update all the fields to 0 and then update the selected ones to 1 afterwards (2 queries but possibly better than the next idea)
    2) Change the form input to something else like radio buttons that will submit both true and false selections and then run either a large query if you can or multiple queries in a loop.

    There is no way to know in php that a check box is not checked unless you store them / their id in a session before printing out the page and then compare what is submitted back from that form against this list.
    I thought a pic would help

    Yes ive been trying to do idea number one but i cannot get it to work. Can you help ? As you can see ive been trying forver. lol

  5. #20
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,346
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Well if you're wanting to use the first option then you first need to run a query to set all column fields to 0...

    update <table> set `column1` = '0', `column2` = '0', `column3` = '0' where `column4` = 'criteria'

    Then just loop through the checkboxes and set those fields to 1 where you have a criteria for your where clause.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  6. Users who have thanked tangoforce for this post:

    DjDanHayden (06-05-2013)

  7. #21
    New Coder DjDanHayden's Avatar
    Join Date
    Nov 2008
    Location
    Ireland
    Posts
    55
    Thanks
    18
    Thanked 0 Times in 0 Posts
    PHP Code:
    $Query "UPDATE cp_rights SET ".$stafflist[abv]."='0' WHERE id='$menulist[id]'"
    Should do that ?

  8. #22
    New Coder DjDanHayden's Avatar
    Join Date
    Nov 2008
    Location
    Ireland
    Posts
    55
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Ok I am an idot..........

    I forgot to put in the query

    mysql_query

    haha it works !!

    Thanks for your help.


 
Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

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