Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

"Select Multiple", retrieving array values on next page, PHP

  • 19-05-2005 07:25PM
    #1
    Registered Users, Registered Users 2, Paid Member Posts: 8,008 ✭✭✭
    Something about sandwiches


    The below code creates an array called "skills[]" and sends to page2.php .
    <form action=page2.php method=get>
    <select name="skills[]" multiple>
    
    <option value="degree">IT DEGREE</option>
    <option value="msce">MSCE</option>
    <option value="fas">FAS</option>
    <option value="diploma">IT DIPLOMA</option>
    <option value="msoffice">MS OFFICE</option>
    <option value="linux">LINUX</option>
    
    </select>
    <input type=submit>
    </form>
    

    The querystring is ".../page2.php?skills%5B%5D=msce&skills%5B%5D=fas" if MSCE and FAS are selected, for example. Problem is i dont know how to access the elements. Google only has examples of sending to the same page and i cant figure out how to adapt them. does anyone know how i can display a list of everything in the array on the following page? i tried
    foreach ($_GET['skills'] as $k => $v)
            {
            echo $skills[$k] . " : " . $skills[$v] ."<br>";
            }
    
    but its not workin.




    /EDIT: actually, it works if i do this:
    $num=count($_GET['skills']);
    echo "You selected " .$num ." choices<br>";
    for ($i = 0 ; $i < $num ; $i++)
            {
            echo $_GET['skills'][$i] ."<br>";
            }
    
    thanks anyway. ;)


Comments

  • Registered Users, Registered Users 2 Posts: 1,268 ✭✭✭hostyle


    foreach ($_GET['skills'] as $k => $v)
            {
            echo $k . " : " . $v ."<br>";
            }
    


Advertisement