SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    dynamic form using checkboxes

    I've been trying to figure out on my own how to get a dynamic checkbox form to work. So far I haven't had too much luck.

    My first example causes the set of 3 checkboxes to repeat for each true statement. On the first set only ATK would be checked, the second set only Beta would be checked, and the last set only BMW would be checked. Close, but no cigar.

    PHP Code:
    $result mysql_query("SELECT * FROM dealerlines WHERE dealerid='$dealerid'",$db);
    while (
    $myrow mysql_fetch_array($result)) {
    $dealerbrand $myrow[dealerbrand];
        if (
    $dealerbrand=="ATK") {
            echo 
    "<input type='checkbox' name='dealerbrand[]' value='ATK' checked> ATK ";
        } else {
            echo 
    "<input type='checkbox' name='dealerbrand[]' value='ATK'> ATK ";
        }
        if (
    $dealerbrand=="Beta") {
            echo 
    "<input type='checkbox' name='dealerbrand[]' value='Beta' checked> Beta";
        } else {
            echo 
    "<input type='checkbox' name='dealerbrand[]' value='Beta'> Beta";
        }
        if (
    $dealerbrand=="BMW") {
            echo 
    "<input type='checkbox' name='dealerbrand[]' value='BMW' checked> BMW";
        } else {
            echo 
    "<input type='checkbox' name='dealerbrand[]' value='BMW'> BMW";
        }


    This example only prints one set of checkboxes, but only the first of three matches is found true, therefore ATK is checked (where Beta and BMW should be as well).


    PHP Code:
    $result mysql_query("SELECT * FROM dealerlines WHERE dealerid='$dealerid'",$db);
    $myrow mysql_fetch_array($result);
    $dealerbrand $myrow[dealerbrand];
        if (
    $dealerbrand=="ATK") {
            echo 
    "<input type='checkbox' name='dealerbrand[]' value='ATK' checked> ATK ";
        } else {
            echo 
    "<input type='checkbox' name='dealerbrand[]' value='ATK'> ATK ";
        }
        if (
    $dealerbrand=="Beta") {
            echo 
    "<input type='checkbox' name='dealerbrand[]' value='Beta' checked> Beta";
        } else {
            echo 
    "<input type='checkbox' name='dealerbrand[]' value='Beta'> Beta";
        }
        if (
    $dealerbrand=="BMW") {
            echo 
    "<input type='checkbox' name='dealerbrand[]' value='BMW' checked> BMW";
        } else {
            echo 
    "<input type='checkbox' name='dealerbrand[]' value='BMW'> BMW";
        } 

    Any tips or pointers?
    - Mike
    http://www.georgiaoffroad.com

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone care to take a stab at this?
    - Mike
    http://www.georgiaoffroad.com

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Once more than I'll quit buggin.

    Btw, if my question doesn't make any sense, please tell me that so I can clarify.

    I'd really appreciate a little guidance here. Thanks!

  4. #4
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would love to help but I still learning PHP. You might want to wait until monday or so. The weekend seems to see a real drop in posting and some of the major PHP players are at rest.

    (how many of them do sitepoint from the office hmmm)
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  5. #5
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm it should work what I always prefer is this:

    PHP Code:
    $result = mysql_query("SELECT * FROM dealerlines WHERE dealerid='$dealerid'",$db);
    while ($myrow = mysql_fetch_array($result)) {
    $dealerbrand = $myrow["dealerbrand"];
        if ($dealerbrand=="ATK") {
            $checked_atk == "checked";
        } 
        if ($dealerbrand=="Beta") {
            $checked_beta = "checked";
        }
        if ($dealerbrand=="BMW") {
            $checked_BMW = "checked";
        }
    ?>
    <input type="checkbox' name='dealerbrand[]' value='ATK' <?=$checked_atk?>> ATK 
    <input type='checkbox' name='dealerbrand[]' value='Beta' <?=$checked_beta?>> Beta
    <input type='checkbox' name='dealerbrand[]' value='BMW' <?=$checked_BMW?>> BMW";
    <?
    }
    Good luck
    the neigbours (free) WIFI makes it just a little more fun


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
  •