SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    challenging checkbox-mySQL problem!!

    helooo people...

    OK.. this is far by the most intriguing problem I've encountered so far. The summarized version is:

    I want to read entries out of a database (these entries are in multiple columns) and have those entries end up as checkbox items. A user can then tick/select those checkbox items, and the corresponding entries will have one of their fields set to 1 or 0 in the database (something like.. since I've selected this, this database row should be set to ON, others remain OFF...)

    Even more simplified:

    Read items off a d/b table, have it end up as checkbox items. Once ticked, write back to d/b table && set corresponding entry to 1.

    Any ideas?

    I've managed to have items end up as checkboxes, and once ticked, ECHO commands will reflect/printout the stuff you checked.

    My code goes like this:

    =========START CODE=========

    if ($submit) {
    foreach($dept as $val)
    print "<br>$val<br>";
    }

    <form action="<?=$PHP_SELF?>" method="post">
    <input type="checkbox" name="dept[]" value="DCS">DCS<br>
    <input type="checkbox" name="dept[]" value="DCE">DCE<br>
    <input type="checkbox" name="dept[]" value="DCA">DCA<br>
    <input type="checkbox" name="dept[]" value="DCB">DCB<br>
    <input type="submit" name="submit" value="Search By Department"><br>
    </form>

    =========END CODE=========

    The items are presently not read off a database.. and I'm not sure how to do that! Sounds like complicated code is required?

  2. #2
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    WHOA! That's some database you've got there... never seen so many columns before

    In principle, your lost pets program is quite easy to understand... all a matter of reading in data, and then assigning it to variables. I think I know how to do it now, but I need to give it some thought still.

    I'll get back to you soon!

  3. #3
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    i was all wet with the lost pets thing. sorry.

    i am reading the wrox item now.

    ed

  4. #4
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hehe... okay.....

    Hmmm. I've gone through your code.. and it's *not quite* what I had in mind.. though I can use certain parts of it....

    What really troubles me now is that for my current system.. I would like that certain entries from a database be converted into checkboxe options. The only way I can think of doing this is via PHP code, and the use of a:

    while (entries are NOT NULL)
    {
    <form action="<?=$PHP_SELF?>" method="post">
    <input type="checkbox"
    name="dept[]"
    value=read from the database, row by row
    </form>
    }

    See where I'm going? Each entry becomes a checkbox. But I can't use PHP for FORMs, can I? Meaning to say PHP and HTML code has to be kept separate. Sigh. This is the part that troubles me.

    I really can't think of another way to do this.. anyone have any ideas?

  5. #5
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    i think i see what you want to do and have read the wrox section (i needed to do that anyhow).

    the wrox parts use a checkbox.html and .php4 for their example and so i keyed it into the editor, and put it on the page at

    http://www.noevalley.com/checkbox.html

    the example is 100 proof the example from the book and you can follow the code with views of the source both the .html and the .php4

    they confirm the code you have as correct as far as the wrox goes. thee other variables, i do not know.

    i will be up for another hour then toast.

    peace

  6. #6
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    YESSSS!! I managed to solve my original problem.. via this code snippet:

    $sql = "SELECT ITEM FROM FOCUSNIGHT WHERE CUR_DATE = 1";
    $result1 = mysql_query($sql); // run query

    $x = mysql_num_fields($result1);
    echo ("$x<BR>");
    ?>

    <form action="<?=$PHP_SELF?>" method="post">

    <?
    while ( $row = mysql_fetch_array($result1) ) {

    for ($y = 0; $y < $x; $y++) {
    ?>
    <input type="checkbox" name="dept[]" value="$row[$y]<BR>"><?echo ("$row[$y]<BR>");?><BR>
    <?
    }
    }


    haha! Hey... how'd you managed to put the code in this area... and have it come out in diff. colors and with a diff. font? That would make it easier for me to post code!


Bookmarks

Posting Permissions

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