1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

php active/deactivate mysql table record

Discussion in 'PHP' started by ianhaney, Nov 21, 2013.

  1. #1
    Hi

    Sorry to ask for help again, have tried looking last night for this little issue

    I want to have a link or checkbox in the backend admin that shows or hides the table record from the front end but on the backend it shows as active or deactive and is easy for the admin user to make it active and deactive by clicking a checkbox or link

    Or same thing but archives the table record to a archive database and then the admin user can move it back from the archive database to the main database

    Is either ways possible, could someone point me in the right direction or send a link that could help me get started

    Kind regards

    Ian
     
    ianhaney, Nov 21, 2013 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Uhm. Very rarely would you need to set a whole table active/not active. I can see how it would be beneficial to be able to hide certain rows in a table, and this can easily be done by adding an "active" column in the given table, and give it a boolean value type (0 or 1). The just check for this when showing records.
     
    PoPSiCLe, Nov 21, 2013 IP
  3. ianhaney

    ianhaney Greenhorn

    Messages:
    72
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #3
    Sorry my mistake, I want the admin user to make active and deactive just certain rows not the whole table, sorry
     
    ianhaney, Nov 21, 2013 IP
  4. ianhaney

    ianhaney Greenhorn

    Messages:
    72
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #4
    Ok I have made a new column called active and gave it a boolean type of 1 for active, how do I make a radio button or checkbox that makes it active and deactive in the php page in the admin backend
     
    ianhaney, Nov 21, 2013 IP
  5. ianhaney

    ianhaney Greenhorn

    Messages:
    72
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #5
    Hi

    I have managed to get the active field entered in the mySQL database using the SET type and entering active and inactive in the values part and managed to get the two radio buttons displayed in the php page but can't work out how to make the record inactive when click the inactive radio button

    The php code is below if it helps

    $active= $row['active'];
    
    echo "<td><input type='radio' name='a'.$active . value='active'>Active <input type='radio' name='a'.$active . value='inactive'>Inactive"."</td>"; 
    PHP:
     
    ianhaney, Nov 21, 2013 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Use values 0 and 1 in your radio buttons. Make sure both buttons have the same name.

    
    <input type="radio" name="active" value="1" />
    <input type="radio" name="active" value="0" />
    
    HTML:
    And in your PHP code:
    
    $db = new PDO(/* ... */);
    $stmt = $db->prepare("
        UPDATE `table-name`
        SET `active` = ?
        WHERE [ ... ]
    ");
    $stmt->execute([(bool) $_POST['active']]);
    
    PHP:
    This way, when you select the 0 value radio button, it'll set it to 0, and 1 otherwise.
     
    nico_swd, Nov 21, 2013 IP