Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,457
    Thanks
    15
    Thanked 0 Times in 0 Posts

    select box to array

    I have a multiple select box named

    <select name=schools[] multiple>

    now my php to retrieve thse is

    $school=$_REQUEST['school'];
    foreach ($school as $k=>$v)
    {
    $sql=$sql."reason like '".$v."%'";
    if ($n>0){
    $sql=$sql." or ";
    }

    now instead of adding each school to the sql it's just writing it out as
    array instead of the school name from the select -- what am i doing wrong?

  • #2
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    PHP Code:
    <?php
    if (!isset($_POST['submit']))
    {
        echo 
    '
        <form action="" method="POST">
        <select name="num[]" size="5" multiple>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
        </select><br>
        <input type="submit" name="submit" value="submit">
        </form>
        '
    ;
    }
    else
    {
        if (isset(
    $_POST['num']))
        {
            foreach (
    $_POST['num'] as $value) {$sql_array[] = "'" $value "'";}
            
    $sql 'SELECT * FROM table WHERE num IN(' implode(','$sql_array) . ')';
            echo 
    $sql;
        }
        else
        {
            echo 
    'you did not select any numbers';
        }
    }
    ?>

  • #3
    Senior Coder
    Join Date
    May 2004
    Posts
    1,457
    Thanks
    15
    Thanked 0 Times in 0 Posts
    will this work with request also?
    as that is what i did but it doesn't seem to work


  •  

    Posting Permissions

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