#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    10
    Rep Power
    0
    Hi everybody,

    I have the following problem, I have 2 columns in my mysql dbase which values are either y or n. So far so good... Now I'm working on an edit page to edit the data from the dbase and would like the checkboxes to show the current value (checked if y, unchecked if n) and I want to be able to change the value and submit it to an update command. Can anybody out there help me out??

    Thanks a lot in advance!!!

    peace

    cube
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    This probably isn't the most effecient way to do this but it worked for me:

    <html>
    <head>
    <title>Untitled</title>
    </head>

    <body>
    <?php
    //Some config stuff change to fit your site
    $dbhost = "";
    $dbuser = "";
    $dbpass = "";
    $dbname = "";

    if (!($db = mysql_connect($dbhost, $dbuser, $dbpass))) echo "error connecting to ". $dbname ."on ". $dbhost;
    mysql_select_db($dbname,$db);

    //This happens after the submit
    //I basically set them all to no and then loop through the array of checked items and set them to yes
    if ($submit) {
    $sql = "UPDATE class_cats set cat_name = 'n'";
    $result = mysql_query($sql, $db);

    for ($i=0;$i < count($action_items); $i++) {
    $result = mysql_query("UPDATE class_cats set cat_name = 'y' WHERE id = '$action_items[$i]'", $db);
    }

    }

    //This is the main query to get the current status of each field
    $sql = "SELECT * from class_cats";
    $result = mysql_query($sql, $db);


    ?>

    //This sets up the checkboxes just change the field names to fit your table
    <form action="<?php print $PHP_SELF; ?>" method="post">
    <?php
    while ($row = mysql_fetch_array($result)) {
    if ($row["cat_name"] == "y") {
    printf('<input type="checkbox" name="action_items[]" value="%s" checked>%s<br>', $row["id"], $row["id"]);
    }
    else {
    printf('<input type="checkbox" name="action_items[]" value="%s">%s<br>', $row["id"], $row["id"]);
    }
    }


    ?>
    <center><input type="submit" name="submit" value="Submit"></center>
    </form>
    </body>
    </html>
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    London/UK
    Posts
    91
    Rep Power
    15
    This'll pull them out and give you your two boxes.

    <?
    $sql = "SELECT val1,val2 from table where someID='$id'";
    $res = mysql_query($sql);
    $vals = mysql_fetch_row($res);

    print "<input type="checkbox" name="value"";
    if ($vals["val1"] == "Y") print " CHECKED";
    print ">";
    ?
    I'm not sure why you have 2 columns though?
    surely you'd have one column which is either Y or N, or am I missing something

    bealers



    ------------------
    http://back-end.org
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    10
    Rep Power
    0
    Sorry for the confusion! I have 2 columns which both are y or n! One will tell if an item is still in stock and the other is placing a certain graphic on the webpage or not.

    The person that maintains the webpage, will end up on this page where he/she can make changes to an item that is already in the dbase, so if the item is in stock the "in Stock" box will be checked, and if he/she uncheckes it and hit the update button the value will be changed to the dbase.

    Thanks both for pointing me in to the right direction. I have some more info now so I should be able to solve my puzzle:-)

    cube

Similar Threads

  1. Replies: 3
    Last Post: March 5th, 2004, 08:08 AM
  2. Zip code validation
    By krwyth in forum MySQL Help
    Replies: 2
    Last Post: January 5th, 2004, 01:29 PM
  3. how to edit db like email removal using checkbox
    By climber in forum PHP Development
    Replies: 5
    Last Post: December 8th, 2003, 01:33 PM
  4. Replies: 3
    Last Post: November 24th, 2003, 09:35 AM
  5. w3c strict errors (10), css, and js questions
    By WorldBuilder in forum CSS Help
    Replies: 12
    Last Post: November 6th, 2003, 04:48 AM

IMN logo majestic logo threadwatch logo seochat tools logo