• User

    inserire array multiplo in db

    Ciao, cercherò di spiegarmi al meglio...

    sto creando uno script.
    prendo i dati da un form e li inserisco in un db, quasi tutto ok ma trovo difficoltà quando nel form ci sono scelte multiple da un elenco. volevo sapere se è più corretto creare una insert per ogni scelta multipla oppure inserire le varie opzioni selezionate in un solo campo tabella (a mio parere sembra una soluzione più ordinata...)

    ecco il codice (funziona tutto meno l'insert multiplo)

    FORM

    echo "<form  method='post' action='../submit_t.php' enctype='multipart/form-data' />
     
       <table border='0' cellpadding='4' cellspacing='1' class='bg2' align='center'>
       <tr><td nowrap='nowrap' class='bg6'>"._XD_MODNAME." - "._XD_TRA."  </td></tr>
       
       
       <tr><td colspan='3'><SELECT NAME=prog_cat value='$prog_cat' >$coptions</SELECT> </td></tr>
       
       <tr><td nowrap='nowrap' class='bg3' colspan='3'>"._XD_TRANAME." </td></tr>
       
       <tr><td colspan='3'><input type='text' name='prog_title'  size='31' maxlength='255' value='$prog_title' /></td></tr>
       
       <tr class='bg3'><td>"._XD_DAY."</td><td>"._XD_START."</td><td>"._XD_END."</td></tr>
       <tr><td ><select size=1  NAME='prog_day' value='$prog_day'  maxlength='255' />
         
         <OPTION value=1> "._XD_DAY1."   <!-- Lunedi -->
         <OPTION Value=2> "._XD_DAY2."   <!-- Martedi -->
         <OPTION value=4> "._XD_DAY3."   <!-- Mercoledi -->
         <OPTION Value=8> "._XD_DAY4." <!-- Giovedi -->
         <OPTION Value=16> "._XD_DAY5." <!-- Venerdi -->
         <OPTION Value=32> "._XD_DAY6." <!-- Sabato -->
         <OPTION value=64> "._XD_DAY0." <!-- Domenica -->
         </select>
        </td> 
        <td><select size=1  NAME='prog_start' value='$prog_start'  />";
         for ($i=0; $i<=23;$i++){
         echo "<option value='$i:00'>$i:00</option>
         <option value='$i:30'>$i:30</option>";
               }
         echo 
         "</select>
        </td>
        <td><select size=1 NAME='prog_end' value='$prog_end'/>";
        for ($i=0; $i<=23;$i++){
        echo "<option value='$i:00'>$i:00</option>
        <option value='$i:30'>$i:30</option>";
              }
         echo
         "</select>
        </td>
       </tr>
     
        
    <tr><td nowrap='nowrap' class='bg3' colspan='3'>"._XD_TRADJ." </td></tr><br />
    <tr><td class='bg3' colspan='3'>"._XD_TRADJMULTI."  </td></tr><br />
    <tr><td colspan='3'><SELECT NAME=prog_dj[] multiple='5' cols='30' value='$prog_dj'>$djoptions</SELECT></td></tr>
     
    <tr><td nowrap='nowrap' class='bg3' colspan='3'>"._XD_DESC."</td></tr><br />
    <tr><td colspan='3'><textarea name='prog_desc' size='50' tabindex='4' wrap='virtual' cols='50' rows='10' value='$prog_desc'  /></textarea></td></tr>
    <tr><td nowrap='nowrap' class='bg3' colspan='3'>"._XD_NOTE."</td></tr><br />
    <tr><td colspan='3'><textarea name='prog_note' tabindex='4' wrap='virtual' cols='30' rows='5' value='$prog_note'  /></textarea></td></tr> 
      
      
    <tr><td nowrap='nowrap' class='bg3' colspan='3'>"._XD_IMAGE." </td></tr><tr><td>
    <input type='hidden' name='MAX_FILE_SIZE' value='100000' />
    <input type='file' name='image_file' size='31' /><br />
    <input type='hidden' name='upload_file[]' id='upload_file[]' value='image_file' /></td></tr>
     
    <tr><td height='20'></td></tr>
    <tr><td colspan='3'><input type='submit' name='add' tabindex='5' value='"._TE_SUBMIT_SAVE."'> <input type='reset' tabindex='6' value='"._TE_ADD_SUBMIT_RESET."'></td>
     </tr></table></form>";
    

    il campo multiplo preleva i dati da un'altra tabella ed è quello con la variabile prog_dj, dj_options stampa l'elenco dei nomi che vado a selezionare (selezione multipla)

    Pagina di invio

    $q = "INSERT INTO ".$xoopsDB->prefix()."_palinsesto_prog (prog_cat, prog_title, prog_desc, prog_img, prog_start, prog_end, prog_dj, prog_day, prog_note) VALUES ('".$prog_cat."','".$prog_title."', '".$prog_desc."', '".$prog_img."', '".$prog_start.":00', '".$prog_end.":00', '".$prog_dj."', '".$prog_day."', '".$prog_note."')";