Check boxes to array to SQL query

Discussion in 'PHP' started by mnymkr, Jun 18, 2008.

  1. #1
    it is possible to pass checkboxes to a GET URL as an array and the insert them into a mysql query to find all items that were checked
     
    mnymkr, Jun 18, 2008 IP
  2. melol2

    melol2 Active Member

    Messages:
    511
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    80
    #2
    sure as long as they are in the form and they have a value and a name they should be sent in the GET along with the rest of the values
     
    melol2, Jun 18, 2008 IP
  3. mnymkr

    mnymkr Well-Known Member

    Messages:
    2,328
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    120
    #3
    oh maybe i asked wrong, how would you do that
     
    mnymkr, Jun 18, 2008 IP
  4. melol2

    melol2 Active Member

    Messages:
    511
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    80
    #4
    <input type="checkbox" name="pie" value="pie">
     
    melol2, Jun 18, 2008 IP
  5. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #5
    Just to clarify, that in a form would result in ?pie=pie if checked.

    Dead simple really.

    The best way to retrieve checkbox statuses is probably isset($_GET['pie']), after all, for a checkbox all that matters is - if its set or not.

    Dan
     
    Danltn, Jun 19, 2008 IP
  6. dreamcon

    dreamcon Peon

    Messages:
    90
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    <input type="checkbox" id=checkbox name="pie" value="on">
     
    dreamcon, Jun 19, 2008 IP
  7. mnymkr

    mnymkr Well-Known Member

    Messages:
    2,328
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    120
    #7
    i am sorry , i am talking about passing mulitple checkbox to the URL

    so it would be

    <input type="checkbox" id=checkbox name="pie[]" value="on">
    <input type="checkbox" id=checkbox name="pie[]" value="on">
    <input type="checkbox" id=checkbox name="pie[]" value="on">


    when it passes to the URL is passes as pie=array

    then i implode it to query

    my problem is that i need to pass it back to my pagination and sort URLs and I am not sure how to do that.
     
    mnymkr, Jun 21, 2008 IP
  8. greatpree

    greatpree Guest

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Hey i got yr point. i have not time right now. so try it later. ok.
     
    greatpree, Jun 22, 2008 IP
  9. greatpree

    greatpree Guest

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    First of all get checkboxes values. creat a string of that values and pass it as hidden variable of form. then u can fetch that value in pagination.

    it's like

    <html>
    <head>
    <script language="javascript">
    function myPieData(val)
    {
    document.getElementById("pieData").value = val;
    }

    </script>
    </head>
    <body>
    <?php
    $val = 'Test';
    if($_POST)
    {

    $checkData = $_REQUEST['pie'];

    if(count($checkData) > 0)
    {
    $val = implode(",",$checkData);
    }
    else
    {
    $val = "";
    }

    echo "<script language='javascript'>myPieData('".$val."');</script>";
    }
    ?>
    <form name="frm" action="checkboxUrl.php" method="post">
    <input type="hiddent" name="pieData" id="pieData"/>
    <input type="checkbox" id=checkbox name="pie[]" value="a">
    <input type="checkbox" id=checkbox name="pie[]" value="b">
    <input type="checkbox" id=checkbox name="pie[]" value="c">
    <input type="submit" name="btnSubmit" value="Submit">
    </form>
    </body>
    </html>
     
    greatpree, Jul 4, 2008 IP