Results 1 to 7 of 7

Thread: looping query?

  1. #1
    Join Date
    Jun 2005
    Location
    coronado
    Posts
    76

    Red face looping query?

    I have a question. I have a mysql query which runs fine and return the proper records, what I'm trying to do is provide three checkboxes in order to sort be priority (A, B, or C). With the help of rawhide, I found out how to perform a sort if the $priority variable is set. The problem im having is this, since the user can opt to sort by either A, B ect (more than 1), How do I run the sql query for as many times as the $priority Variable is set?
    Thanks.

  2. #2
    Join Date
    Feb 2003
    Posts
    1,048
    Give the fields the same name and values of A, B, and C (or whatever). If more than one checkbox is checked, the values will be returned comma delimited.

    Examples:

    No checkboxes checked, value of form element = empty
    Checkbox A checked only, value of form element = A
    Checkbox A and C checked, value of form element = A,C

    Then use these values in your query.

  3. #3
    Join Date
    Jun 2005
    Location
    coronado
    Posts
    76

    Red face

    ok, i did that, I'm noticed that once I select two checkboxes and press go (which submits the form using the method of GET, the URL looks like this.
    ...?priority=A&priority=B&poc=test+medivas+%281%29
    The priority variable isn't comma delimited, and the query seems to only be run on the 2nd priority variable. Do you know why this is?
    Last edited by lukeurtnowski; 07-01-2005 at 01:41 PM.

  4. #4
    Join Date
    Feb 2003
    Posts
    1,048
    post your new code please.

  5. #5
    Join Date
    Jun 2005
    Location
    coronado
    Posts
    76

    Talking

    thanks, here's the php...
    PHP Code:
    if (!isset($priority)) {
    $sql="select *, DATE_FORMAT(a_date, '%m/%d/%Y') as a_date_formatted from company, activity where c_id=a_c_id and medivas ='$poc' order by priority asc";
    $query=mysql_query($sql);
    $numofrows mysql_num_rows($query);
    } else if (isset(
    $priority)) {
    $sql="select *, DATE_FORMAT(a_date, '%m/%d/%Y') as a_date_formatted from company, activity where c_id=a_c_id and medivas ='$poc' and priority ='$priority'";
    $query=mysql_query($sql) or die(mysql_error());
    $numofrows mysql_num_rows($query);

    And here are the three checkboxes...
    PHP Code:
    <form action="" method=GET>
        <table BORDER="0" CLASS="priority" ALIGN="CENTER" WIDTH="100%">
        <tr><th rowspan=3>Sort by Priority:</Th><th>
        A:<INPUT TYPE="Checkbox" NAME="priority" VALUE="A">
        </th><th rowspan=3>
        <input type=submit value=Go class=btp>
        </TH></tr><tr><th>
        B:<INPUT TYPE="Checkbox" NAME="priority" VALUE="B">
        </Th></TR><tr><th>
        C:<INPUT TYPE="Checkbox" NAME="priority" VALUE="C">
        </Th></tr></TABLE>
    <input type=hidden name=poc VALUE="<?php echo $_GET['poc']; ?>">
    </FORM>
    You can see the form by making a selection (test medivas (1)) on the combo box on the far right...
    http://www.lukesplace.com/Padilla/createreport.php
    thanks,thanks,thannks
    Last edited by lukeurtnowski; 07-01-2005 at 02:21 PM.

  6. #6
    Join Date
    Feb 2003
    Posts
    1,048
    After researching it, it appears that PHP handles it differently than ASP does. Rather than being a comma delimited string, it's returned as an array. So you need to access it as an array.

    There's some good info on the subject here: http://us4.php.net/variables.external
    Last edited by Rawhide; 07-01-2005 at 02:45 PM.

  7. #7
    Join Date
    Jun 2005
    Location
    coronado
    Posts
    76
    k, thanks....
    you da man

Posting Permissions

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