Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    [php]Numeri, assegnare valori alle cifre

    Ho 8 campi numerici che vanno da 0 a 30.

    Vorrei poter dare, per ogni campo, questi valori:
    - per ogni punto minore di 10, 1 punto;
    - per ogni punto tra 10 e 20, 2 punti;
    - per ogni punto tra 20 e 30, 3 punti;

    esempio:
    un campo con valore 25 da un punteggio di:

    (25-10)*1+((25-20)*2+i restanti 5*3

    però così sarebbe veramente macchinoso..un modo +veloce?
    GdR Online - http://lenar.it/
    Yesterday is history. Tomorrow is mystery.
    Today is a gift. That's why it's called the present

  2. #2
    Utente di HTML.it L'avatar di gianiaz
    Registrato dal
    May 2001
    Messaggi
    8,027
    Codice PHP:
    GNU nano 1.2.4                  File: switch.php

    <?php
    switch(TRUE) {
      case (
    $a<10):
      
    $punti=1;
      break;
      case (
    $a>=10 && $a <20):
      
    $punti=2;
      break;
      case (
    $a>=20 && $a <30):
      
    $punti=3;
      break;

    }
    echo 
    $punti;
    ?>
    Ho capito bene?

  3. #3
    switch (TRUE) di cosa fa lo switch?
    in questo caso non è che se un punteggio e minore di 10 gli da punteggio 1, se è tra 10 e 20 gli da 2...ecc.?

    Io vorrei che se fosse il punteggio 12:
    poiché ci sono 10 numeri compresi tra 0 e 10 (12-10) abbiamo

    $punteggio=10;

    poiché ci sono 2 numeri tra 10 e 20:

    $punteggio+=2*2;
    GdR Online - http://lenar.it/
    Yesterday is history. Tomorrow is mystery.
    Today is a gift. That's why it's called the present

  4. #4
    Moderatore di Server Apache L'avatar di marketto
    Registrato dal
    Sep 2001
    Messaggi
    5,858
    codice:
    $numero = 25;
    if($numero < 10)
    	$temp = $numero;
    elseif($numero < 20)
    	$temp = 10 + ($numero - 10) * 2;
    else
    	$temp = 10 + 20 + ($numero - 20) * 3;
    echo $temp;


    think simple think ringo

  5. #5
    bello..giusto^_^

    Grazie.
    GdR Online - http://lenar.it/
    Yesterday is history. Tomorrow is mystery.
    Today is a gift. That's why it's called the present

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.