Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 12

Discussione: somma

  1. #1

    somma

    questa e' la funziona per la somma

    codice:
    mysql_select_db($database_camera, $camera);
    $query_Recordset2 = "SELECT SUM(quota)FROM soldi";
    $Recordset2 = mysql_query($query_Recordset2, $camera) or die(mysql_error());
    $row_Recordset2 = mysql_fetch_assoc($Recordset2);
    $totalRows_Recordset2 = mysql_num_rows($Recordset2);
    
    echo $row_Recordset2;
    Ho provato ance con
    codice:
    $query_Recordset2 = "SELECT SUM(quota) as soldi FROM soldi";
    Il campo quota e' di tipo decimal,ma ho provato anche con float

    perche' come risultato mi da ARRAY?

  2. #2
    codice:
    mysql_select_db($database_camera, $camera);
    $query_Recordset2 = "SELECT SUM(quota) FROM soldi";
    $Recordset2 = mysql_query($query_Recordset2, $camera) or die(mysql_error());
    $row_Recordset2 = mysql_fetch_row($Recordset2);
    $totalRows_Recordset2 = mysql_num_rows($Recordset2);
    
    echo $row_Recordset2[0];
    perche' il result set ti arriva come array.

    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

  3. #3
    grazie

  4. #4
    Adesso volevo tirarmi fuori solo i dati di un cliente con la relativa somma di quello che ha pagato (quota)

    codice:
    mysql_select_db($database_camera, $camera);
    $query_Recordset2 = "SELECT SUM(quota) as totale FROM soldi GROUP BY numero_cliente";
    $Recordset2 = mysql_query($query_Recordset2, $camera) or die(mysql_error());
    $row_Recordset2 = mysql_fetch_row($Recordset2);
    $totalRows_Recordset2 = mysql_num_rows($Recordset2);
    ma da dei numeri a casaccio

  5. #5
    codice:
    $query_Recordset2 = "SELECT SUM(quota) as totale 
                                 FROM soldi 
                                 where cliente = 'tuo cliente'
                                 GROUP BY numero_cliente";

    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

  6. #6
    ma se da una pagina che mi mostra tutti i clienti estratti da un'altra tabella e faccio un collegamento sul numero cliente:

    codice:
    pagamenti.php?recordNUMERO_CLIENTE=<?php echo $row_Recordset1['numero_cliente'];
    logicamente nella pagina pagamenti ho due form uno (Recordset1) per la tabella dove mi estrae il numero_cliente-nome-cognome-quota e l'altro (Recordset2) il quale mi deve restituire la somma.
    come faccio?

    la query che mi hai detto e' obbligata al ('tuo cliente'),e mi darà sempre il valore riferito solo a quel cliente,ma in realtà mi deve variare a secondo di quale cliente seleziono

    codice:
    $query_Recordset2 = "SELECT SUM(quota) as totale 
                                 FROM soldi 
                                 where cliente = 'tuo cliente'
                                 GROUP BY numero_cliente";
    spero di aver spiegato nel miglior dei modi visto che in italiano mmm....lasciamo stare

  7. #7
    In pratica non ho capito.

    nel where mettici un variabile che si adegui al cliente... ma boh!!!

    where cliente = '$variabile'

    ma un form, un altro form.... :master:

    se vuoi dire che devi estrarre due campi dal db... mettici due campi nel select.

    anche in teoria non ho capito...

    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

  8. #8
    Questo e' il codice

    codice:
    <?php require_once('Connections/camera.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
    
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
    
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }
    
    $colname_Recordset1 = "-1";
    if (isset($_GET['recordNUMERO_SOCIO'])) {
      $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['recordNUMERO_SOCIO'] : addslashes($_GET['recordNUMERO_SOCIO']);
    }
    mysql_select_db($database_camera, $camera);
    $query_Recordset1 = sprintf("SELECT * FROM soldi WHERE numero_socio = %s", GetSQLValueString($colname_Recordset1, "text"));
    $Recordset1 = mysql_query($query_Recordset1, $camera) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    
    mysql_select_db($database_camera, $camera);
    $query_Recordset2 = "SELECT SUM(quota) as totale FROM soldi where numero_socio = '$numero_socio' GROUP BY numero_socio";
    $Recordset2 = mysql_query($query_Recordset2, $camera) or die(mysql_error());
    $row_Recordset2 = mysql_fetch_row($Recordset2);
    $totalRows_Recordset2 = mysql_num_rows($Recordset2);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Documento senza titolo</title>
    <style type="text/css">
    <!--
    .Stile1 {
    	font-size: 12px;
    	font-weight: bold;
    }
    .Stile2 {font-size: 12px}
    -->
    </style>
    </head>
    <body>
    
    
    </p>
    <form id="form1" name="form1" method="post" action="">
      <table border="1">
        <tr>
          <td><div align="center" class="Stile1">numero_socio</div></td>
          <td><div align="center" class="Stile1">cognome</div></td>
          <td><div align="center" class="Stile1">nome</div></td>
          <td><div align="center" class="Stile1">data</div></td>
          <td><div align="center" class="Stile1">quota</div></td>
        </tr>
        <?php do { ?>
          <tr>
            <td><div align="center"><span class="Stile2"><?php echo $row_Recordset1['numero_socio']; ?></span></div></td>
            <td><div align="center"><span class="Stile2"><?php echo $row_Recordset1['cognome']; ?></span></div></td>
            <td><div align="center"><span class="Stile2"><?php echo $row_Recordset1['nome']; ?></span></div></td>
            <td><div align="center"><span class="Stile2"><?php echo $row_Recordset1['data']; ?></span></div></td>
            <td><div align="center"><span class="Stile2"><?php echo $row_Recordset1['quota']; ?></span></div></td>
                  </tr>]; ?></span></div></td>
          </tr>
          <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
      </table>
    </form>
    <form id="form2" name="form2" method="post" action="">
      <hr />
      <table width="787" border="1">
        <tr>
          <td width="335"><span class="Stile2">
                 </span></td>
          <td width="291"><span class="Stile2"><?php echo $row_Recordset2[0]; ?></span></td>
          <td width="139"></td>
        </tr>
      </table>
    </form>
    </body>
    </html>
    <?php
    mysql_free_result($Recordset1);
    ?>

  9. #9
    ma non e' il codice che non ho capito. E' la domanda

    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

  10. #10
    Inanzi tutto ti ringrazio per l'interessamento.
    Questo è quello che mi hai postato
    codice:
    $query_Recordset2 = "SELECT SUM(quota) as totale 
                                 FROM soldi 
                                 where cliente = 'tuo cliente'
                                 GROUP BY numero_cliente";
    Adesso io al posto di 'tuo cliente' devo mettere il numero_cliente,ma il questo modo mi restituira' sempre il valore riferito a quel cliente,se io richiamo un'altro cliente il risultato della somma non e' giusto.
    Ho provato anche a sostituire al posto di 'tuo cliente'con la variabile '$numero_cliente',ma in questo modo non mi restituisce niente.

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 © 2025 vBulletin Solutions, Inc. All rights reserved.