Visualizzazione dei risultati da 1 a 6 su 6

Discussione: Array (forse)

  1. #1

    Array (forse)

    Ciao a tutti,
    sto cercando di convertire un codice che avevo scritto da asp in php. In pratica ho una pagina in cui ho una serie di giocatori (il numero è variabile) e ad ognuno di essi devo assegnare un punteggio:
    Giocatore1 5punti
    Giocatore2 3punti
    ...
    Quando invio la pagina mi ritrovo i valori solo dell'ultimo giocatore (nell'es sarebbe Giocatore2 3punti), mentre in asp mi trovavo "Giocatore1,Giocatore2 5punti,3punti".
    Come faccio a recuperare tutti i valori?
    Posto qui sotto solo una parte del codice, se serve posso postare tutta la pagina (ma è piuttosto lunga)

    Grazie
    codice:
    	$query3=mysql_query("select * from ruoli where ruolo='$_ruolo'") or die(mysql_error());
    	while ($row3=mysql_fetch_assoc($query3))
    	{
    	$_p1n=$row3['p1'];
    	$_p2n=$row3['p2'];
    	$_p3n=$row3['p3'];
    	$_p4n=$row3['p4'];
    	echo '<td><div id=smallboxalto2><center>[b]'.$_nome1.' - '.$_ruolo.'</div><div id=smallboxcentro2>';
    	echo '<table border=0 width=295>';
    
    	echo '<tr><td witdh=183>'.$_p1n.'</td><td width=110>';
    	echo '<input type="hidden" id="gioc" name="gioc" value="'.$_nome1.'" style="width: 20px;">';
    	echo '<input type="button" id="'.$_nome1.'_p1_minus" name="'.$_nome1.'_p1_minus" value="-" onclick="aumenta(\''.$_nome1.'_p1\', -1)" disabled=disabled>';
    	echo '<input type="text" id="'.$_nome1.'_p1" name="p1" value="'.$_p1.'" style="width: 50px;" readonly=readonly>';
    	echo '<input type="button" id="'.$_nome1.'_p1_plus" name="'.$_nome1.'_p1_plus" value="+" onclick="aumenta(\''.$_nome1.'_p1\', 1)">';
    	echo '<input type="hidden" id="'.$_nome1.'_p1_val" name="'.$_nome1.'_p1_val" value="'.$_p1.',10000" />';
    	echo '</td></tr>';

  2. #2
    Moderatore di Off Topic, Kickstarter e XML L'avatar di Sky
    Registrato dal
    Jul 2000
    residenza
    Roma
    Messaggi
    1,053
    Con la funzione array_pop() estrai l'ultimo valore di un array

    Qui trovi tutte le informazioni su di essa: http://www.php.net/manual/en/function.array-pop.php
    Ciao
    Lo Stato deve dare ai cittadini, come diritto, ciò che la mafia dà come favore.
    Carlo Alberto dalla Chiesa

    Facebook | Twitter | Last.fm | LinkedIn | Quora

  3. #3
    nella pagina che riceve il submit metti un

    Codice PHP:

    print_r
    ($_POST
    e controlla che cosa c'è nell'array di POST. Poi ricontrolla l'html generato dal tuo script e cerca di capire se il risultato che il post produce è corretto o errrato a causa di un errore di html.
    IP-PBX management: http://www.easypbx.it

    Old account: 2126 messages
    Oldest account: 3559 messages

  4. #4
    Questo il risultato

    Array ( [tot] => 88 [gioc] => t3 [p1] => 1 [a1_p1_val] => 3,10000 [p2] => 1 [a1_p2_val] => 3,10000 [p3] => 1 [a1_p3_val] => 3,10000 [p4] => 1 [a1_p4_val] => 3,10000 [a2_p1_val] => 3,10000 [a2_p2_val] => 3,10000 [a2_p3_val] => 3,10000 [a2_p4_val] => 3,10000 [a3_p1_val] => 3,10000 [a3_p2_val] => 3,10000 [a3_p3_val] => 3,10000 [a3_p4_val] => 3,10000 [t1_p1_val] => 1,10000 [t1_p2_val] => 1,10000 [t1_p3_val] => 1,10000 [t1_p4_val] => 1,10000 [t2_p1_val] => 1,10000 [t2_p2_val] => 1,10000 [t2_p3_val] => 1,10000 [t2_p4_val] => 1,10000 [t3_p1_val] => 1,10000 [t3_p2_val] => 1,10000 [t3_p3_val] => 1,10000 [t3_p4_val] => 1,10000 )

    Quello che noto è che come giocatore c'è solo t3 (l'ultimo in una pagina con 6 giocatori)

  5. #5
    Originariamente inviato da dydale
    Questo il risultato

    Array ( [tot] => 88 [gioc] => t3 [p1] => 1 [a1_p1_val] => 3,10000 [p2] => 1 [a1_p2_val] => 3,10000 [p3] => 1 [a1_p3_val] => 3,10000 [p4] => 1 [a1_p4_val] => 3,10000 [a2_p1_val] => 3,10000 [a2_p2_val] => 3,10000 [a2_p3_val] => 3,10000 [a2_p4_val] => 3,10000 [a3_p1_val] => 3,10000 [a3_p2_val] => 3,10000 [a3_p3_val] => 3,10000 [a3_p4_val] => 3,10000 [t1_p1_val] => 1,10000 [t1_p2_val] => 1,10000 [t1_p3_val] => 1,10000 [t1_p4_val] => 1,10000 [t2_p1_val] => 1,10000 [t2_p2_val] => 1,10000 [t2_p3_val] => 1,10000 [t2_p4_val] => 1,10000 [t3_p1_val] => 1,10000 [t3_p2_val] => 1,10000 [t3_p3_val] => 1,10000 [t3_p4_val] => 1,10000 )

    Quello che noto è che come giocatore c'è solo t3 (l'ultimo in una pagina con 6 giocatori)
    se c'è solo un giocatore sarà sbagliato l'html del form che invia. Devi controllare quello.
    IP-PBX management: http://www.easypbx.it

    Old account: 2126 messages
    Oldest account: 3559 messages

  6. #6
    Non ci capisco niente

    Questo è il codice completo della pagina:

    codice:
    <?php
    include 'zzz.inc';
    include 'update.inc';
    include 'top.inc';
    include 'punti.inc';
    include 'nav1.inc';
    include 'alto.inc';
    ?>
    
    <script type="text/javascript" language="JavaScript">
    function aumenta(nome, value) {     
        strValori = document.getElementById(nome+"_val").value.split(",");    //Recupera i valori minimo e massimo per ogni gruppo
    
        strValoreMin = strValori[0];
        strValoreMax = strValori[1];    
         
        tot_input = document.getElementById("tot");
        changed_input = document.getElementById(nome);
             
        tot = 1*tot_input.value;
        changed = 1*changed_input.value;
    
        if ((tot - value)<0) {
            alert("Hai esaurito le risorse a disposizione")
        } else {     
            if ((changed + value)>=strValoreMax) {
                document.getElementById(nome+"_plus").disabled="disabled";
                tot_input.value = tot - value;
                changed_input.value = changed + value;
            } else if ((changed + value)<(parseInt(strValoreMin)+1)) {
                document.getElementById(nome+"_minus").disabled="disabled";
                tot_input.value = tot - value;
                changed_input.value = changed + value;
            } else {
                document.getElementById(nome+"_plus").disabled=false;
                document.getElementById(nome+"_minus").disabled=false;
                tot_input.value = tot - value;
                changed_input.value = changed + value;
            }         
        }
    }
    
    
    </script>
    
    <center><div id=bigboxalto><center>[b]Distribuisci risorse</div><div id=bigboxcentro><table border=0 width=610><tr><td align=justify>Qui puoi ditribuire le tue risorse come ritieni piu' opportuno. Pensa attentamente a come distribuire i punti di cui disponi. Cliccando su "Accetta" non sara' possibile annullare l'operazione.
    
    </td></tr><tr><td>
    
    <form name=modulo method=post action=distr2.php>
    <?php
    $_nome=$_SESSION['nome'];
    $_id=$_SESSION['codice'];
    $_all='';
    $query1=mysql_query("select * from users where username='$_nome'") or die(mysql_error());
    while ($row1=mysql_fetch_assoc($query1))
    {
    $_id=$row1['codice'];
    
    $_squadra=$row1['squadra'];
    $query10=mysql_query("select * from risorse where user='$_id'") or die(mysql_error());
    while ($row10=mysql_fetch_assoc($query10))
    {
    $_totris=$row10['punti'];
    echo '<center>Punti disponibili: <input type="text" id="tot" name="tot" value="'.$_totris.'" style="width: 40px;" readonly>';
    echo '
    
    Giocatori attuali:
    </center>';
    echo '<table border=0 width=600><tr>';
    $query2=mysql_query("select * from giocatori where squadra='$_squadra'") or die(mysql_error());
    $_x=0;
    $_y=1;
    while ($row2=mysql_fetch_assoc($query2))
    {
    $_ruolo=$row2['ruolo'];
    $_nome1=$row2['nome'];
    $_p1=$row2['p1'];
    $_p2=$row2['p2'];
    $_p3=$row2['p3'];
    $_p4=$row2['p4'];
    
    	$query3=mysql_query("select * from ruoli where ruolo='$_ruolo'") or die(mysql_error());
    	while ($row3=mysql_fetch_assoc($query3))
    	{
    	$_p1n=$row3['p1'];
    	$_p2n=$row3['p2'];
    	$_p3n=$row3['p3'];
    	$_p4n=$row3['p4'];
    	echo '<td><div id=smallboxalto2><center>[b]'.$_nome1.' - '.$_ruolo.'</div><div id=smallboxcentro2>';
    	echo '<table border=0 width=295>';
    
    	echo '<tr><td witdh=183>'.$_p1n.'</td><td width=110>';
    	echo '<input type="hidden" id="gioc" name="gioc" value="'.$_nome1.'" style="width: 20px;">';
    	echo '<input type="button" id="'.$_nome1.'_p1_minus" name="'.$_nome1.'_p1_minus" value="-" onclick="aumenta(\''.$_nome1.'_p1\', -1)" disabled=disabled>';
    	echo '<input type="text" id="'.$_nome1.'_p1" name="p1" value="'.$_p1.'" style="width: 50px;" readonly=readonly>';
    	echo '<input type="button" id="'.$_nome1.'_p1_plus" name="'.$_nome1.'_p1_plus" value="+" onclick="aumenta(\''.$_nome1.'_p1\', 1)">';
    	echo '<input type="hidden" id="'.$_nome1.'_p1_val" name="'.$_nome1.'_p1_val" value="'.$_p1.',10000" />';
    	echo '</td></tr>';
    
    	echo '<tr><td witdh=183>'.$_p2n.'</td><td width=110>';
    	echo '<input type="hidden" id="gioc" name="gioc" value="'.$_nome1.'" style="width: 20px;">';
    	echo '<input type="button" id="'.$_nome1.'_p2_minus" name="'.$_nome1.'_p2_minus" value="-" onclick="aumenta(\''.$_nome1.'_p2\', -1)" disabled=disabled>';
    	echo '<input type="text" id="'.$_nome1.'_p2" name="p2" value="'.$_p2.'" style="width: 50px;" readonly=readonly>';
    	echo '<input type="button" id="'.$_nome1.'_p2_plus" name="'.$_nome1.'_p2_plus" value="+" onclick="aumenta(\''.$_nome1.'_p2\', 1)">';
    	echo '<input type="hidden" id="'.$_nome1.'_p2_val" name="'.$_nome1.'_p2_val" value="'.$_p2.',10000" />';
    	echo '</td></tr>';
    
    	echo '<tr><td witdh=183>'.$_p3n.'</td><td width=110>';
    	echo '<input type="hidden" id="gioc" name="gioc" value="'.$_nome1.'" style="width: 20px;">';
    	echo '<input type="button" id="'.$_nome1.'_p3_minus" name="'.$_nome1.'_p3_minus" value="-" onclick="aumenta(\''.$_nome1.'_p3\', -1)" disabled=disabled>';
    	echo '<input type="text" id="'.$_nome1.'_p3" name="p3" value="'.$_p3.'" style="width: 50px;" readonly=readonly>';
    	echo '<input type="button" id="'.$_nome1.'_p3_plus" name="'.$_nome1.'_p3_plus" value="+" onclick="aumenta(\''.$_nome1.'_p3\', 1)">';
    	echo '<input type="hidden" id="'.$_nome1.'_p3_val" name="'.$_nome1.'_p3_val" value="'.$_p3.',10000" />';
    	echo '</td></tr>';
    
    	echo '<tr><td witdh=183>'.$_p4n.'</td><td width=110>';
    	echo '<input type="hidden" id="gioc" name="gioc" value="'.$_nome1.'" style="width: 20px;">';
    	echo '<input type="button" id="'.$_nome1.'_p4_minus" name="'.$_nome1.'_p4_minus" value="-" onclick="aumenta(\''.$_nome1.'_p4\', -1)" disabled=disabled>';
    	echo '<input type="text" id="'.$_nome1.'_p4" name="p4" value="'.$_p4.'" style="width: 50px;" readonly=readonly>';
    	echo '<input type="button" id="'.$_nome1.'_p4_plus" name="'.$_nome1.'_p4_plus" value="+" onclick="aumenta(\''.$_nome1.'_p4\', 1)">';
    	echo '<input type="hidden" id="'.$_nome1.'_p4_val" name="'.$_nome1.'_p4_val" value="'.$_p4.',10000" />';
    	echo '</td></tr>';
    
    	echo '</table></div><div id=smallboxbasso2></div></td>';
    $_y=$_y+1;
    
    	}
    
    if ($_y==3) {
    echo "</tr><tr>";
    $_y=1;
    }
    $_x=$_x+1;
    
    }
    //
    
    
    
    
    }
    echo '</table>';
    $_SESSION['all']=$_all;
    
    $_SESSION['x']=$_x;
    }
    echo '<center><input type=submit value=Accetta></form></td></tr></table></div><div id=bigboxbasso></div>';
    include 'basso.inc';
    ?>
    Da tutto questo a me serve recuperare i valori di gioc,p1,p2,p3,p4.

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.