Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11
  1. #1

    Vedere record database in un radio button

    Buona sera a tutti, ho un piccolo problema con i radio button...
    ho questo form:
    Codice PHP:
    <form name="modulo" id="test" action="profilo.php?azione=esegui" method="post" onsubmit="return ControllaTutto(this);">
    <
    input type="hidden" name="done" /> 
    ...
    ...


    Tuo Genere:</p>
         
    Maschile:<input type="radio" name="sex" value='0'>

         
    Femminile:<input type="radio" name="sex" value='1'>

    ...
    ...
    <
    input type="submit" value="   OK   ">
    </
    form
    Utilizzo un semplice $_POST per salvare i dati nel db.

    Come faccio invece a visualizzare checkato as esempio il primo radio se nel db c'è value 0?

    Grazie per l'aiuto

  2. #2
    Codice PHP:
    <?php
    $sex_prelevato_da_db 
    1;

    $check0 '';
    $check1 '';
    switch(
    $sex_prelevato_da_db)
        {
        case 
    0:
            
    $check0 .= ' checked="checked"';
        case 
    1:
            
    $check1 .= ' checked="checked"';
        }

    echo 
    '
            Maschile:<input type="radio" name="sex" value="0"'
    .$check0.'>
     
            Femminile:<input type="radio" name="sex" value="1"'
    .$check1.'>
    '
    ;
    ?>

  3. #3
    me lo sono adattato così:
    Codice PHP:
    <?php
    $result 
    mysql_query("  
            select * 
            from pannellomod  
            WHERE username = '"
    .$user."'  
            LIMIT 1"
    ) or die(mysql_error()); 
    $righi mysql_fetch_array($result); 
    $sex=$righi['genere'];
    $sex 1

    $check0 ''
    $check1 ''
    switch(
    $sex
        { 
        case 
    0
            
    $check0 .= ' checked="checked"'
        case 
    1
            
    $check1 .= ' checked="checked"'
        } 

    echo 

            

    Tuo Genere:</p>
            Maschile:<input type="radio" name="sex" value="0"'
    .$check0.'>
      
            Femminile:<input type="radio" name="sex" value="1"'
    .$check1.'>
    '

    ?>
    ma stranamente mi checka sempre "femminile" anche se nel db cambio mettendo 0 come valore.

  4. #4
    cancella
    $sex = 1;

  5. #5
    Già avevo provato prima di postare il code, ma vedendo che lo stesso non andava l'ho postato.
    Continua a non andare quindi...

  6. #6
    dopo
    $sex=$righi['genere'];

    scrivi

    echo $sex;

    e vedi cosa stampa (e se stampa...)

  7. #7
    mmm davvero strano, stampa ciò che è scritto nel db (quindi 0), ma nella radio box rimane sempre femminile (quindi 1)...

  8. #8
    cambia lo switch mettendo gli apici
    Codice PHP:
    switch($sex)  
        {  
        case 
    '0':  
            
    $check0 .= ' checked="checked"';  
        case 
    '1':  
            
    $check1 .= ' checked="checked"';  
        } 

  9. #9
    continua a non andare

  10. #10
    sono io il deficiente... ora funziona al 100%

    Codice PHP:
    switch($sex)   
        {   
        case 
    '0':   
            
    $check0 .= ' checked="checked"';   break;
        case 
    '1':   
            
    $check1 .= ' checked="checked"';   break;
        } 

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.