Paste: PHP : Arrau

Author: Script
Mode: factor
Date: Mon, 24 Feb 2014 08:26:06
Plain Text |
<?php
mysql_connect("mysql.hostinger.ro", "u433511535_loto", "parola") or die(mysql_error());
mysql_select_db("u433511535_loto") or die(mysql_error());

$numere_cautate = false;
if (isset($_POST['numere'])) {
    $search_text = str_replace(" ", "", trim($_POST['numere']));
    if (!empty($search_text)) {
        $numere_cautate = explode(",", $search_text);
    }
}

$search_text = isset($search_text) ? $search_text : "";

$limit = isset($_POST['extrageri']) ? $_POST['extrageri'] : 10;
$limit = is_numeric($limit) ? $limit : 10;

$ultimele_zile = isset($_POST['ultimele_zile']) ? $_POST['ultimele_zile'] : 3;
$ultimele_zile = is_numeric($ultimele_zile) ? $ultimele_zile : 3;
?>

<!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=utf-8" />
    <link rel="stylesheet" href="style.css" type="text/css" media="all" />
    <script src="js/sorttable.js"></script>
    <title>Loto Polonia</title>
</head>
<body>

<div id="search">
    <form method="post" action="index.php">
        <input type="text" placeholder="Numere" name="numere" size="30" value="<?php echo $search_text; ?>">
        <input type="text" placeholder="Extrageri" name="extrageri" size="5" value="<?php echo $limit; ?>">
        <select name="ultimele_zile">
            <option value="1">Ultima zi</option>
            <option value="2">Ultimele 2 zile</option>
            <option value="3" selected="selected">Ultimele 3 zile</option>
            <option value="4">Ultimele 4 zile</option>
            <option value="5">Ultimele 5 zile</option>
            <option value="0">Toată baza de date</option>
        </select>
        <input type="submit" value="Caută">
    </form>    
</div>


<table id="box-table-a" class="sortable" style="float: left; margin: 0 15px 15px 0; text-align: center;">
    <thead>
        <tr>
            <th scope="col">Nr.</th>
            <th scope="col">Aparitii</th>
            <th scope="col">Pauza</th>
            <th scope="col">Pauza max.</th>
            <th scope="col">Media</th>
        </tr>
    </thead>
    <tbody>
        <?php
        if (is_array($numere_cautate)) {
            $cu_limita = ($ultimele_zile == 0) ? "" : "AND data >= (CURDATE() - INTERVAL $ultimele_zile DAY )";
            
            foreach ($numere_cautate as $numar_cautat) {
                echo '<tr>';
                echo '<td>'.$numar_cautat.'</td>';
                echo '<td>';            
                $aparitii = mysql_num_rows(mysql_query("SELECT * FROM extrageri WHERE FIND_IN_SET('".$numar_cautat."', numere) > 0 ".$cu_limita." ORDER BY id DESC "));
                echo $aparitii;
                echo '</td>';
                
                $prima_pauza = false;
                $pauza = $pauza_curenta = $pauza_maxima = 0;            
                $ultimele_extrageri = mysql_query("SELECT * FROM extrageri WHERE id ".$cu_limita." ORDER BY id DESC");
                $numar_ultimele_extrageri = mysql_num_rows($ultimele_extrageri);
                while ($rand = mysql_fetch_assoc($ultimele_extrageri)) {
                    $numere = str_replace(" ", "", $rand['numere']);
                    $numere_array = explode(",", $numere);
                    
                    if (!in_array($numar_cautat, $numere_array)) {
                        $pauza++;    
                        if ($pauza > $pauza_maxima) $pauza_maxima = $pauza;    
                    } else {
                        if ($prima_pauza == false) {
                            $pauza_curenta = $pauza;
                            $prima_pauza = true;
                            $pauza = 0;
                        }
                    }            
                    
                    if ($aparitii == 0) $pauza_curenta = $pauza_maxima = $numar_ultimele_extrageri;
                }
                $medie = number_format(($aparitii * 100)/$numar_ultimele_extrageri, 2);
                echo '<td>'.$pauza_curenta.'</td>';
                echo '<td>'.$pauza_maxima.'</td>';
                echo '<td>'.$medie.'%</td>';
                echo '</tr>';    
            }
        }
           ?>
    </tbody>
</body>
</html>

New Annotation

Summary:
Author:
Mode:
Body: