Stampa ne DB moltissime righe

  • Creatore Discussione Creatore Discussione Shyson
  • Data di inizio Data di inizio

Shyson

Utente Attivo
19 Ago 2012
1.179
1
38
Come si può vedere dal mio sito a dx, nell'area Sondaggio hanno votato 5 persone www.gruppoalveo.altervista.org ma stampa un'enorme quantità di righe nel DB
Il codice è questo:

PHP:
<?php
$q="SELECT * FROM sondaggio WHERE id=1"; 
$risultato = mysql_query($q); 
$riga=mysql_fetch_assoc($risultato); 
$tot=0; // Metto il totale a 0 
foreach($riga as $chiave => $valore) { 
     if($chiave !="id") {
        ${$chiave}=$valore; // Valore del campo 
        $tot=$tot+$valore; // Faccio il totale 
    } 
} 
// Definisce le variabili
$rx="";
$gx=""; 
$dx=""; 
$tx=""; 
$wx=""; 
$cx=""; 
$mx=""; 
$ax="";      

if($tot >0) {
     $data_localeS=time();
     $dataGmtS=$giorno[date('w')].' '.date('d').' '.$mese[date('m')-1].' '.date('Y - H:i:s \G\M\T P');
     $ip=$_SERVER['REMOTE_ADDR'];  
     $rx=$radio; // Stampa il numero di votanti
     $r=$radio/$tot*100; $radio_pos=(int)$r-100; // Mette la percentuale
     $radio=number_format($r, 1, ',',''); // Mette il decimale 
  if($radio >=100){$radio=(int)$radio;}  // Toglie il decimale a 100%
     $gx=$giornali; 
     $g=$giornali/$tot*100; $giornali_pos=(int)$g-100; 
     $giornali=number_format($g, 1, ',',''); 
  if($giornali >=100){$giornali=(int)$giornali;} 
     $dx=$depliant;
     $d=$depliant/$tot*100; $depliant_pos=(int)$d-100; 
     $depliant=number_format($d, 1, ',',''); 
  if($depliant >=100){$depliant=(int)$depliant;} 
  	 $tx=$televisione;    
     $t=$televisione/$tot*100; $televisione_pos=(int)$t-100; 
     $televisione=number_format($t, 1, ',',''); 
  if($televisione >=100){$televisione=(int)$televisione;}  
  	 $wx=$web_banner;   
     $w=$web_banner/$tot*100; $web_banner_pos=(int)$w-100; 
     $web_banner=number_format($w, 1, ',','');  
  if($web_banner >=100){$web_banner=(int)$web_banner;}  
  	 $cx=$casualmente;  
     $c=$casualmente/$tot*100; $casualmente_pos=(int)$c-100; 
     $casualmente=number_format($c, 1, ',',''); 
  if($casualmente >=100){$casualmente=(int)$casualmente;}  
  	 $mx=$motori_di_ricerca;   
     $m=$motori_di_ricerca/$tot*100; $motori_di_ricerca_pos=(int)$m-100; 
     $motori_di_ricerca=number_format($m, 1, ',','');  
  if($motori_di_ricerca >=100){$motori_di_ricerca=(int)$motori_di_ricerca;}  
  	 $ax=$amici_o_conoscenti;    
     $a=$amici_o_conoscenti/$tot*100; $amici_o_conoscenti_pos=(int)$a-100;
     $amici_o_conoscenti=number_format($a, 1, ',',''); 
  if($amici_o_conoscenti >=100){$amici_o_conoscenti=(int)$amici_o_conoscenti;}     
}
else {
     $radio=0; $radio_pos=-100;
     $giornali=0; $giornali_pos=-100;
     $depliant=0; $depliant_pos=-100;
     $televisione=0; $televisione_pos=-100;
     $web_banner=0; $web_banner_pos=-100;
     $casualmente=0; $casualmente_pos=-100;
     $motori_di_ricerca=0; $motori_di_ricerca_pos=-100;
     $amici_o_conoscenti=0; $amici_o_conoscenti_pos=-100;
}
if(isset($_POST['puls_invio'])) { 
if(!isset($_COOKIE['votato'])) { //Setta il cookie (2/4), il primo si trova in connessione.php
if(isset($_POST['voto'])) {
    $voto=mysql_real_escape_string($_POST['voto']);
    $q="UPDATE sondaggio SET $voto = $voto + 1 WHERE id=1";           
    if(mysql_query($q)) { 
    echo "Il tuo voto è stato inserito!"; 
    echo "<meta http-equiv='refresh' content='2; url=".htmlspecialchars($_SERVER['PHP_SELF'])."'>"; 
    setcookie("votato", "si", time()+259200); // Dura 3 giorni, setta il cookie (3/4)
  
  // Inserisce i dati EXTRA nella tabella
$q=mysql_query("INSERT INTO sondaggio(data_localeS,dataGmtS,ip,country)  
                           VALUES('$data_localeS','$dataGmtS','$ip','".$countries[$two_letter_country_code][1]."')");                           
                                                                 
// Estrae i dati dalla tabella    
$q="SELECT * FROM sondaggio"; 
 }
  } 
else { 
     echo "Devi selezionare una risposta!";  
     echo "<meta http-equiv='refresh' content='2; url=".htmlspecialchars($_SERVER['PHP_SELF'])."'>"; 
   }
} 
else { 
    echo "Hai già votato, grazie!";   
    echo "<meta http-equiv='refresh' content='2; url=".htmlspecialchars($_SERVER['PHP_SELF'])."'>"; 
   } 
} 
?>
//FORM

Questa è una piccola parte delle righe che stampa

PHP:
-- Struttura della tabella `sondaggio`
--

CREATE TABLE IF NOT EXISTS `sondaggio` (
  `id` int(1) NOT NULL AUTO_INCREMENT,
  `data_localeS` varchar(100) NOT NULL,
  `dataGmtS` varchar(100) NOT NULL,
  `radio` int(12) NOT NULL,
  `giornali` int(12) NOT NULL,
  `depliant` int(12) NOT NULL,
  `televisione` int(12) NOT NULL,
  `web_banner` int(12) NOT NULL,
  `casualmente` int(12) NOT NULL,
  `motori_di_ricerca` int(12) NOT NULL,
  `amici_o_conoscenti` int(12) NOT NULL,
  `ip` varchar(20) NOT NULL,
  `country` varchar(100) NOT NULL,
  KEY `id` (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;

--
-- Dump dei dati per la tabella `sondaggio`
--

INSERT INTO `sondaggio` (`id`, `data_localeS`, `dataGmtS`, `radio`, `giornali`, `depliant`, `televisione`, `web_banner`, `casualmente`, `motori_di_ricerca`, `amici_o_conoscenti`, `ip`, `country`) VALUES
(1, '0', '0', 0, 0, 0, 0, 0, 2, 1, 2, '0', '0'),
(2, '0', '0', 0, 0, 0, 0, 0, 0, 0, 0, '0', 'Italy'),
(3, '1377872632', 'Venerd&igrave; 30 agosto 2013 - 16:23:52 GMT +02:00', 0, 0, 0, 0, 0, 0, 0, 0, '78.5.138.92', 'Italy'),
(4, '1385137766', 'Venerd&igrave; 22 novembre 2013 - 17:29:26 GMT +01:00', 0, 0, 0, 0, 0, 0, 0, 0, '79.59.3.204', 'Italy'),
(1, '0', '0', 0, 0, 0, 0, 0, 2, 1, 2, '0', '0'),
(2, '0', '0', 0, 0, 0, 0, 0, 0, 0, 0, '0', 'Italy'),
(3, '1377872632', 'Venerd&igrave; 30 agosto 2013 - 16:23:52 GMT +02:00', 0, 0, 0, 0, 0, 0, 0, 0, '78.5.138.92', 'Italy'),
(4, '1385137766', 'Venerd&igrave; 22 novembre 2013 - 17:29:26 GMT +01:00', 0, 0, 0, 0, 0, 0, 0, 0, '79.59.3.204', 'Italy'),
(1, '0', '0', 0, 0, 0, 0, 0, 2, 1, 2, '0', '0'),
(2, '0', '0', 0, 0, 0, 0, 0, 0, 0, 0, '0', 'Italy'),
(3, '1377872632', 'Venerd&igrave; 30 agosto 2013 - 16:23:52 GMT +02:00', 0, 0, 0, 0, 0, 0, 0, 0, '78.5.138.92', 'Italy'),
(4, '1385137766', 'Venerd&igrave; 22 novembre 2013 - 17:29:26 GMT +01:00', 0, 0, 0, 0, 0, 0, 0, 0, '79.59.3.204', 'Italy'),
(5, '1391801143', 'Venerd&igrave; 07 febbraio 2014 - 20:25:43 GMT +01:00', 0, 0, 0, 0, 0, 0, 0, 0, '95.247.28.15', 'Italy'),
(6, '1393092616', 'Sabato 22 febbraio 2014 - 19:10:16 GMT +01:00', 0, 0, 0, 0, 0, 0, 0, 0, '79.47.18.234', 'Italy'),
(1, '0', '0', 0, 0, 0, 0, 0, 2, 1, 2, '0', '0'),
(2, '0', '0', 0, 0, 0, 0, 0, 0, 0, 0, '0', 'Italy'),
(3, '1377872632', 'Venerd&igrave; 30 agosto 2013 - 16:23:52 GMT +02:00', 0, 0, 0, 0, 0, 0, 0, 0, '78.5.138.92', 'Italy'),
(4, '1385137766', 'Venerd&igrave; 22 novembre 2013 - 17:29:26 GMT +01:00', 0, 0, 0, 0, 0, 0, 0, 0, '79.59.3.204', 'Italy'),
(1, '0', '0', 0, 0, 0, 0, 0, 2, 1, 2, '0', '0'),
(2, '0', '0', 0, 0, 0, 0, 0, 0, 0, 0, '0', 'Italy'),
(3, '1377872632', 'Venerd&igrave; 30 agosto 2013 - 16:23:52 GMT +02:00', 0, 0, 0, 0, 0, 0, 0, 0, '78.5.138.92', 'Italy'),
(4, '1385137766', 'Venerd&igrave; 22 novembre 2013 - 17:29:26 GMT +01:00', 0, 0, 0, 0, 0, 0, 0, 0, '79.59.3.204', 'Italy'),
(1, '0', '0', 0, 0, 0, 0, 0, 2, 1, 2, '0', '0'),
(2, '0', '0', 0, 0, 0, 0, 0, 0, 0, 0, '0', 'Italy'),
(3, '1377872632', 'Venerd&igrave; 30 agosto 2013 - 16:23:52 GMT +02:00', 0, 0, 0, 0, 0, 0, 0, 0, '78.5.138.92', 'Italy'),
(4, '1385137766', 'Venerd&igrave; 22 novembre 2013 - 17:29:26 GMT +01:00', 0, 0, 0, 0, 0, 0, 0, 0, '79.59.3.204', 'Italy'),
(5, '1391801143', 'Venerd&igrave; 07 febbraio 2014 - 20:25:43 GMT +01:00', 0, 0, 0, 0, 0, 0, 0, 0, '95.247.28.15', 'Italy'),
(6, '1393092616', 'Sabato 22 febbraio 2014 - 19:10:16 GMT +01:00', 0, 0, 0, 0, 0, 0, 0, 0, '79.47.18.234', 'Italy'),
...
 

Discussioni simili