Problema con query

  • Creatore Discussione Creatore Discussione Trapano
  • Data di inizio Data di inizio
ciao
le variabili semplici no, gli array non so, guardo sul manuale


allora da
http://php.net/manual/en/language.types.string.php
Example #2 Heredoc string quoting example
le variabili semplici no con le graffe, gli array si

PHP:
<?php
//...
$foo = new foo();
$name = 'MyName';

echo <<<EOT
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should print a capital 'A': \x41
EOT;
?>
che da in out
My name is "MyName". I am printing some Foo.
Now, I am printing some Bar2.
This should print a capital 'A': A
 
Ultima modifica:
Ancora errore alla riga " echo <<<TAB "....
Ma ad ogni modo per la pagina ho risolto... mi manca soltanto di riuscire a far la somma del campo "rimborso"... mi risulta campo vuoto....
 
ciao
metti due var_dump e guarda cosa risulta ed eventualmente posta il risultato
PHP:
<?php
//....
 while($riga=mysql_fetch_array($risultati)){
        var_dump($riga['rimborso']);
		$rimborso +=$riga['rimborso'];
		var_dump($rimborso);
        echo <<< RIS 
//......
?>
li ho messi nel mio script, ma se l'hai cambiato dovresti capire dove metterli
 
Allora... con questo script, mi funziona tutto tranne la somma.
PHP:
<?php

 $txt = $_POST['txt'];
 $username="XXX";
 $password="XXX";
 $database="XXX";
 $b=date('d/m/y');
 
 mysql_connect(localhost,$username,$password);
 @mysql_select_db($database) or die("Impossibile selezionare il database.");
 $query="SELECT * FROM oggetti WHERE id_venditore LIKE '%$txt%' ORDER BY venduto DESC";
 
 $risultati=mysql_query($query);
 
 $num=mysql_numrows($risultati);
 
mysql_close(); 

 $i=0;
 
 while ($i < $num) {
    
     $id=mysql_result($risultati,$i,"id");
     $id_venditore=mysql_result($risultati,$i,"id_venditore");
     $descrizione=mysql_result($risultati,$i,"descrizione");
     $prezzo=mysql_result($risultati,$i,"prezzo");
     $quantita=mysql_result($risultati,$i,"quantita");
     $percento=mysql_result($risultati,$i,"percento");
     $provvigione=mysql_result($risultati,$i,"provvigione");
     $rimborso=mysql_result($risultati,$i,"rimborso");
     $venduto=mysql_result($risultati,$i,"venduto");
 $data_vendita=mysql_result($risultati,$i,"data_vendita");
 $pagamento=mysql_result($risultati,$i,"pagamento");
     
 
 echo "<table align='center' bgcolor='white' border='1' height='' width='900' cellpadding='0' cellspacing='0'>";
 echo "<tr>";
 echo "<td align='center' width=''><b>id oggetto</b></td>";
 echo "<td align='center' width=''><b>id venditore</b></td>";
 echo "<td align='center' width=''><b>Descrizione</b></td>";
 echo "<td align='center' width=''><b>Prezzo</b></td>";
 echo "<td align='center' width=''><b>Quantita'</b></td>";
 echo "<td align='center' width=''><b>%</b></td>";
 echo "<td align='center' width=''><b>Provvigione</b></td>";
 echo "<td align='center' width=''><b>Rimborso</b></td>";
 echo "<td align='center' width=''><b>Stato</b></td>";
 echo "<td align='center' width=''><b>Data vendita</b></td>";
 echo "<td align='center' width=''><b>Pagamento</b></td>";
 echo "</tr>";
 echo "<td align='center'width=''>$id</td>";
 echo "<td align='center'width=''>$id_venditore</td>";
 echo "<td align='center'width=''>$descrizione</td>";
 echo "<td align='center' width=''>$prezzo euro</td>";
 echo "<td align='center' width=''>$quantita</td>";
 echo "<td align='center' width=''>$percento %</td>";
 echo "<td align='center' width=''>$provvigione euro</td>";
 echo "<td align='center' width=''>$rimborso euro</td>";
 echo "<td align='center' width=''>$venduto</td>";
 echo "<td align='center'width=''>$data_vendita</td>";
 echo "<td align='center'width=''>$pagamento</td>";
 echo "</table><br>";
  
     $i++;
     
 }
   
 ?>
<br>
<table align='center' bgcolor='white' border='0' height='' width='900' cellpadding='0' cellspacing='0'>
<td align='center'><font color='black' size='3'>
Totale oggetti = <?php echo "$num"; ?><br>
Rimborso di oggetti venduti fino al <?php echo $b ?> =  <?php QUI CI VORREI LA SOMMA ?> <input text=""></font><br><br>
<font color='black' size='2'>Va allegata ad ogni eventuale precedente lista di oggetti rimborsati.<br><a href='javascript:print();'>stampa </a></font></td></table>



Dove dovrei inserire il tuo script?
 
Ultima modifica di un moderatore:
ciao
a parte che devi sempre racchiudere il codice tra gli appositi tag (seconda riga formattazione del post ultime tre iconcine nell'ordine CODE, HTML, PHP) mi spieghi perche per estrarre i dati usi quel ca..no?
 
Avete ragione.... ma io sono autodidatta che fa questo per hobbies!!!!
Ci ragiono un po'... copio incollo... e faccio molte prove...
Non so nemmeno se si possono inserire due while consecutivi...
Ti prego aiutami... ;-)
 
PHP:
<?php
$txt = $_POST['txt'];
$username = "XXX";
$password = "XXX";
$database = "XXX";
$b = date('d/m/y');

mysql_connect(localhost, $username, $password);
@mysql_select_db($database) or die("Impossibile selezionare il database.");
$query = "SELECT * FROM oggetti WHERE id_venditore LIKE '%$txt%' ORDER BY venduto DESC";

$risultati = mysql_query($query);

$num = mysql_numrows($risultati);

mysql_close();

$i = 0;
$totale_rimborso = 0;
while ($i < $num) {

    $id = mysql_result($risultati, $i, "id");
    $id_venditore = mysql_result($risultati, $i, "id_venditore");
    $descrizione = mysql_result($risultati, $i, "descrizione");
    $prezzo = mysql_result($risultati, $i, "prezzo");
    $quantita = mysql_result($risultati, $i, "quantita");
    $percento = mysql_result($risultati, $i, "percento");
    $provvigione = mysql_result($risultati, $i, "provvigione");
    $rimborso = mysql_result($risultati, $i, "rimborso");
    $venduto = mysql_result($risultati, $i, "venduto");
    $data_vendita = mysql_result($risultati, $i, "data_vendita");
    $pagamento = mysql_result($risultati, $i, "pagamento");

    $totale_rimborso = $totale_rimborso + $rimborso;

    echo "<table align='center' bgcolor='white' border='1' height='' width='900' cellpadding='0' cellspacing='0'>";
    echo "<tr>";
    echo "<td align='center' width=''><b>id oggetto</b></td>";
    echo "<td align='center' width=''><b>id venditore</b></td>";
    echo "<td align='center' width=''><b>Descrizione</b></td>";
    echo "<td align='center' width=''><b>Prezzo</b></td>";
    echo "<td align='center' width=''><b>Quantita'</b></td>";
    echo "<td align='center' width=''><b>%</b></td>";
    echo "<td align='center' width=''><b>Provvigione</b></td>";
    echo "<td align='center' width=''><b>Rimborso</b></td>";
    echo "<td align='center' width=''><b>Stato</b></td>";
    echo "<td align='center' width=''><b>Data vendita</b></td>";
    echo "<td align='center' width=''><b>Pagamento</b></td>";
    echo "</tr>";
    echo "<td align='center'width=''>$id</td>";
    echo "<td align='center'width=''>$id_venditore</td>";
    echo "<td align='center'width=''>$descrizione</td>";
    echo "<td align='center' width=''>$prezzo euro</td>";
    echo "<td align='center' width=''>$quantita</td>";
    echo "<td align='center' width=''>$percento %</td>";
    echo "<td align='center' width=''>$provvigione euro</td>";
    echo "<td align='center' width=''>$rimborso euro</td>";
    echo "<td align='center' width=''>$venduto</td>";
    echo "<td align='center'width=''>$data_vendita</td>";
    echo "<td align='center'width=''>$pagamento</td>";
    echo "</table><br>";

    $i++;
}
?>
<br>
<table align='center' bgcolor='white' border='0' height='' width='900' cellpadding='0' cellspacing='0'>
    <td align='center'><font color='black' size='3'>
        Totale oggetti = <?php echo "$num"; ?><br>
        Rimborso di oggetti venduti fino al <?php echo $b ?> =  <?php echo $totale_rimborso ?> <input text=""></font><br><br>
        <font color='black' size='2'>Va allegata ad ogni eventuale precedente lista di oggetti rimborsati.<br><a href='javascript:print();'>stampa </a></font></td></table>
 
SSSSIiiiiiiiiiiiii!!!! Grazieeeeeeee.... Proprio come volevo!!!
Ora tutto funziona alla perfezione!!! Grazie...
Se passi da Pontedera e bevi birra... fai un fischio!!!!Ne hai una pagata! ;-)
 
Ora vediamo se posso approfittare ancora... tanto già che siam qui...
Allora.... In pratica faccio un elenco con gli oggetti venduti e sommo la cifra per rimborsarli al cliente.
Ma se la settimana prossima vendo altri oggetti dello stesso cliente e devo rimborsarli, mi ritornano nell'elenco anche quelli che ho già rimborsato.
La query che ho al momento è questa:
$query="SELECT * FROM oggetti WHERE id_venditore LIKE '%$txt%' && pagamento = 'Pagato' ORDER BY venduto DESC";
e il tuo script per la somma è questo:
$totale_rimborso = $totale_rimborso + $rimborso;

Potrei togliere la scritta "&& pagamento = 'Pagato'" in modo da visualizzare anche quelli non venduti ma in questo caso la somma non sarebbe la realtà...
Mmmm e poi sarei allo stesso punto perchè in futuro se vendessi un altro oggetto, mi ricomparirebbe la lista con tutti gli oggetti precedenti...
Allora? Come dovrei organizzare la cosa?
 
ciao
se vuoi togliere && pagamento = 'Pagato' nel while metti una if
PHP:
<?php
//....
$pagamento = mysql_result($risultati, $i, "pagamento");
	if($pagamento == "Pagato"){
    	$totale_rimborso = $totale_rimborso + $rimborso; 
	}
//....
?>
quindi il rimborso si somma solo per gli articoli che sono stati pagati
poi se come dici vuoi vedere gli articoli da un certo periodo nel form dovresti mettere anche un campo data e modificare la query
PHP:
$query="SELECT * FROM oggetti WHERE id_venditore LIKE '%$txt%' && pagamento = 'Pagato' &&  data_vendita >= $data ORDER BY venduto DESC";
però qui bisogna sapere come sono salavate le date (timestamp, formato umano americano, formato umano italiano ?) se sono in formato umano italiano, cioè gg mm aaaa è un casino
 
Grazie mille ragazzi.
Alla fine ho risolto il tutto così... e funziona.
PHP:
<?php
 $txt = $_POST['txt'];
 $username="XXX";
 $password="XXXXXX";
 $database="XXXXXXX";
 $b=date('d/m/y');
 mysql_connect(localhost,$username,$password);
 @mysql_select_db($database) or die("Impossibile selezionare il database.");
 $query="SELECT * FROM oggetti WHERE id_venditore LIKE '%$txt%' && data_vendita = '$b' ORDER BY id DESC";
 $risultati=mysql_query($query);
 $num=mysql_numrows($risultati);
mysql_close(); 
 $i=0;
 while ($i < $num) {
     $id=mysql_result($risultati,$i,"id");
     $id_venditore=mysql_result($risultati,$i,"id_venditore");
     $descrizione=mysql_result($risultati,$i,"descrizione");
     $prezzo=mysql_result($risultati,$i,"prezzo");
     $quantita=mysql_result($risultati,$i,"quantita");
     $percento=mysql_result($risultati,$i,"percento");
     $provvigione=mysql_result($risultati,$i,"provvigione");
     $rimborso=mysql_result($risultati,$i,"rimborso");
     $venduto=mysql_result($risultati,$i,"venduto");
 $data_vendita=mysql_result($risultati,$i,"data_vendita");
 $pagamento=mysql_result($risultati,$i,"pagamento");
$totale_rimborso = $totale_rimborso + $rimborso;
$totale_provvigione = $totale_provvigione + $provvigione;     
 echo "<table align='center' bgcolor='white' border='1' height='' width='900' cellpadding='0' cellspacing='0'>";
 echo "<tr>";
 echo "<td align='center' width='50'><b>id oggetto</b></td>";
 echo "<td align='center' width='50'><b>id venditore</b></td>";
 echo "<td align='center' width='500'><b>Descrizione</b></td>";
 echo "<td align='center' width='50'><b>Prezzo</b></td>";
 echo "<td align='center' width='50'><b>Quantita'</b></td>";
 echo "<td align='center' width='30'><b>%</b></td>";
 echo "<td align='center' width='30'><b>Provvigione</b></td>";
 echo "<td align='center' width='30'><b>Rimborso</b></td>";
 echo "<td align='center' width='30'><b>Pagamento</b></td>";
 echo "<td align='center' width='30'><b>Data rimborso</b></td>";
 echo "</tr>";
 echo "<td align='center'width=''>$id</td>";
 echo "<td align='center'width=''>$id_venditore</td>";
 echo "<td align='center'width=''>$descrizione</td>";
 echo "<td align='center' width=''>$prezzo euro</td>";
 echo "<td align='center' width=''>$quantita</td>";
 echo "<td align='center' width=''>$percento %</td>";
 echo "<td align='center' width=''>$provvigione euro</td>";
 echo "<td align='center' width=''>$rimborso euro</td>";
 
 echo "<td align='center'width=''>$pagamento</td>";
 echo "<td align='center'width=''>$data_vendita</td>";
 echo "</table><br>";
     $i++;
 }
 ?>
<br>
<table align='center' bgcolor='white' border='0' height='' width='900' cellpadding='0' cellspacing='0'>
<td align='center'><font color='black' size='3'>
Totale oggetti = <?php echo "$num"; ?><br>
Rimborso di oggetti venduti fino al <?php echo $b ?> =  <b><?php echo $totale_rimborso ?> euro</b>
<br>
Provvigione per oggetti venduti fino al <?php echo $b ?> =  <b><?php echo $totale_provvigione - $totale_provvigione/100*21;?> + iva al 21% <?php echo $totale_provvigione/100*21;?> = <?php echo $totale_provvigione ?> euro </b></font><br><br>
<font color='black' size='2'>Va allegata ad ogni eventuale precedente lista di oggetti rimborsati.<br><a href='javascript:print();'>stampa </a></font></td></table><br>
Ho aggiunto il campo "data_rimborso al db, modificato la query e aggiunto la somma delle provvigioni scorporata dell'iva.
Grazie veramente per le dritte.
Credo che il post si possa definire chiuso a meno che non abbiate delle modifiche allo script voi...:fonzie::elvis::byebye:
 
Ultima modifica di un moderatore:
ciao
alcuni appunti
1. ricordati di racchiudere il codice tra gli appositi tag (si legge meglio e si evidenziano alcuni errori se ci fossero)
2. è un po' rigido, leggi solo per la data del server e non a quella che eventualmente vuoi tu (es. ieri)
3. secondo me è un codice che potrebbe essere semplificato
4. ma quasto non è solo il tuo caso, voler salvare le date in formato leggibile (leggibile per l'utente, ma per php indifferente) usando il timestamp o il formato anglosassone si puo fare quello che si vuuole
 
Dopo il grande aiuto che mi avete dato e i problemi che siete stati in grado di risolvermi, vorrei abusare ancora del vostro aiuto.
Vorrei richiamare le email presenti nella casella "email" ma solo quelle dove è presente la mail... quelle vuote non le vorrei visualizzare.
La query che uso al momento è questa...

$sel = $_POST['sel'];
$txt = $_POST['txt'];



SELECT * FROM oggetti WHERE $sel LIKE '%$txt%' ORDER BY id DESC

ma mi elenca anche gli spazzi vuoti.
cosa manca?
Grazie.
 

Discussioni simili