SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast daliren's Avatar
    Join Date
    Oct 2001
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    foreach() question

    I have a situation where the user of my page is supposed to select which licences they hold from a series of checkboxes. upon submitting, they are presented with their choices and asked to select the year and school for each degree. I have no problem getting the selected degrees to display with select boxes beside them, but the select box only contains the last item of the table it is supposed to be displaying. Here's the code. Any ideas? Thanks!


    <td colspan="10" valign="top" align="center"><p>For each License, please select
    the year of licensing</p></td>
    </tr>
    <tr>
    <?php
    if ($lcnse == "") $lcnse = array();

    //HOW CAN I GET ALL OF THIS QUERY TO
    //APPEAR IN THE SELECT BOX???

    $yyyy = mysql_query("select ID, Year from YearDL order by Year asc");
    while ($ann = mysql_fetch_array($yyyy)) {
    $yid = $ann["ID"];
    $yr = $ann["Year"];
    }
    foreach($lcnse as $licID) {
    $license = mysql_query("select Name from License where ID=$licID");
    while ($lic = mysql_fetch_array($license)) {
    $ltype = $lic["Name"];
    echo("<td valign='top' align='center'><fieldset><legend>$ltype</legend>
    <select name='year' size='1'><option selected value=''>year awarded</option>
    <option value='$yid'>$yr</option></fieldset></td>");
    }
    } ?>
    cheers,

    Darren Cassidy

  2. #2
    Feel my RewiredMind KMxRetro's Avatar
    Join Date
    Jan 2001
    Location
    Exeter, Devon, UK
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm no expert, but I *THINK* that you are stating the html <OPTION> and <SELECT> tags for EVERY item in the resultset. Try this...

    <td colspan="10" valign="top" align="center"><p>For each License, please select
    the year of licensing</p></td>
    </tr>
    <tr>
    <td valign='top' align='center'>

    <?php
    if ($lcnse == "") $lcnse = array();


    $yyyy = mysql_query("select ID, Year from YearDL order by Year asc");
    while ($ann = mysql_fetch_array($yyyy)) {
    $yid = $ann["ID"];
    $yr = $ann["Year"];
    }
    foreach($lcnse as $licID) {
    $license = mysql_query("select Name from License where ID=$licID");
    while ($lic = mysql_fetch_array($license)) {
    $ltype = $lic["Name"];

    $selecthold .= "<option value='$yid'>$yr</option>";

    }
    } ?>

    <select name='year' size='1'><option selected value=''>year awarded</option>

    <? echo $selecthold; ?>

    </select></td>


    Not sure if that will work and it's a little rushed (at work atm), but give it a try.

    Cheers,

  3. #3
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you name your checkboxes licences[] when the form is submitted all of the checked items will be in an array called licences

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature


Bookmarks

Posting Permissions

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