Results 1 to 7 of 7

Thread: help with array issues?

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

    help with array issues?

    I have an array ( poc[]) to hold all the selections made in a list box. But when I make any selection, and run the query;
    $sql="select * from company, activity where c_id = a_c_id and
    medivas in ('poc[0]' , '$poc[1]', '$poc[2]', '$poc[3]', '$poc[4]', '$poc[5]') and
    a_date between '{$_POST['startdate']}' and '{$_POST['enddate']}'
    and priority in ('{$_POST['prioritya']}', '{$_POST['priorityb']}', '{$_POST['priorityc']}')
    GROUP BY c_name ORDER BY priority";
    then I echo $sql;
    I get
    select * from company, activity where c_id = a_c_id and medivas in ('', '', '', '', '', '') and a_date between '2001-07-20' and '2005-01-05' and priority in ('A', 'B', 'C') GROUP BY c_name ORDER BY priority

    It looks to me that it not seeing any poc[] variables, why?
    Thanks.

  2. #2
    Join Date
    Apr 2005
    Location
    florida
    Posts
    89
    Can you show us how you fill the Array poc?
    in the meantime, try to add some hard-coded values to the array and test.
    e.g $poc[0]='val0'; $poc[1]='val1'

  3. #3
    Join Date
    Jun 2005
    Location
    coronado
    Posts
    76
    sure, here is how I fill poc[]..
    PHP Code:
    echo "<select name='poc[]' size='" mysql_num_rows($query1) . "' multiple>";
        while(
    $result1 mysql_fetch_assoc($query1)) { 
        
    printf('<option value="'.$result1['medivas'].'">'.$result1['medivas'] . '</option>');
        print 
    "\n";  
                }
        echo 
    "</SELECT>"

  4. #4
    Join Date
    Jun 2005
    Location
    coronado
    Posts
    76
    I tried testing it (like you said and I get the same result?
    select * from company, activity where c_id = a_c_id and medivas in ('') and a_date between '2001-07-20' and '2001-07-20' and priority in ('A', 'B', 'C') GROUP BY c_name ORDER BY priority
    Shouldn't it be ...medivas in ('any')...
    PHP Code:
        echo "<select name='poc[]' size='" mysql_num_rows($query1) . "' multiple>";
    $poc[0] = 'any';
        while(
    $result1 mysql_fetch_assoc($query1)) { 
        
    printf('<option value="'.$result1['medivas'].'">'.$result1['medivas'] . '</option>');
        print 
    "\n";  
                }
        echo 
    "</SELECT>"
    Last edited by lukeurtnowski; 07-20-2005 at 04:02 PM.

  5. #5
    Join Date
    Apr 2005
    Location
    florida
    Posts
    89
    Did you declare an array in the next to recieve the values?

    $ppoc=array();
    $ppoc=$_GET["poc"];


    and try ;
    ...medivas in ('$ppoc[0]' , '$ppoc[1]', '$ppoc[2]', '$ppoc[3]', '$ppoc[4]', '$ppoc[5]')...

  6. #6
    Join Date
    Jun 2005
    Location
    coronado
    Posts
    76
    K, that worked I used echo $sql; to see the result, but now I get another error
    select * from company, activity where c_id = a_c_id and medivas in ('test medivas (2)' , 'test medivas (3)', '', '', '', '')... and a_date between '2001-07-20' and '2001-07-20' and priority in ('A', 'B', 'C') GROUP BY c_name ORDER BY priority
    You have an error in your SQL syntax near '... and a_date between '2001-07-20' and '2001-07-20' and priority in ('A', 'B'' at line 2

  7. #7
    Join Date
    Jun 2005
    Location
    coronado
    Posts
    76
    got it thanks

Posting Permissions

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