0

如何从我的数据库 mysql 上的过滤搜索中生成报告。我想在页面底部创建一个链接“运行报表”,该链接根据搜索结果创建报表 Excel。

很可能我将不得不在单独的页面中创建一个脚本“runreport.php”。

帮我!!!

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <title>Search</title>
        <meta name="author" content="g.calvaruso.ext" />
        <!-- Date: 2013-10-14 -->

        <?php

        include 'conn.php';

        ?>

<link rel="stylesheet" href="../style.css" type="text/css" media="screen" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/blitzer/jquery-ui.css" type="text/css" />
<script src="../js/jquery.easy-confirm-dialog.js"></script>
    <style>

</style>    
    </head>
    <body>

<div id="main">

    <img alt="logoAifa" src="../images/banner.jpg"/>
    <ul class="menu">
    <li><a href="../index.php">Home</a></li>
    <li><a class="msearch">Ricerca </a></li>
    <li><a href="newrecord.php">Inserisci</a></li>
    </ul>

    <table class="search">
                    <tr>
                    <td colspan="3" style="text-align:center"><h4>Ricerca</h4>
                    </td>
                    </tr>

                <form method="post" action="search.php">

                    <tr>
                        <td>ID AIFA</br>
                        <input type="text" placeholder="IDAIFA" name="byidaifa"></td>
                        <td>Nome </br>
                        <input type="text" placeholder="Nome" name="bynome"></td>
                        <td>Cognome </br>
                        <input type="text" placeholder="Cognome" name="bycognome"></td>
                    </tr>

                    <tr>
                        <td>Tipologia</br>
                        <select name="bytipologia">
                            <option value="">Non specificato</option>
                            <option value="Desktop">Desktop</option>
                            <option value="Notebook">Notebook</option>
                            <option value="Stampante">Stampante</option>
                            <option value="Tablet">Tablet</option>
                            <option value="Smartphone">Smartphone</option>
                            <option value="HD Esterno">HD Esterno</option>
                        </select>   
                            </td>
                        <td>Marca </br>
                        <input type="text" placeholder="Marca" name="bymarca"></td>
                        <td>Modello </br>
                        <input type="text" placeholder="Modello" name="bymodello"></td>
                    </tr>

                    <tr>
                        <td>Seriale</br>
                        <input type="text" placeholder="Seriale" name="byseriale"></td>
                        <td>Stato </br>
                        <select name="bystato">
                            <option value="">Non specificato</option>
                            <option value="Assegnato">Assegnato</option>
                            <option value="Da Consegnare">Da Consegnare</option>
                            <option value="Dismesso">Dismesso</option>
                            <option value="Disponibile">Disponibile</option>
                            <option value="In Dismissione">In Dismissione</option>
                            </select>
                        </td>

                        <td>Software</br>
                        <input type="text" placeholder="Software" name="bysoftware"></td>

                    </tr>

                    <tr>
                    <td colspan="3" align="right"><input type="submit" name="submits" value="Go"></td>
                    </tr>
                    </form>
        </table>


        <script>

        $( ".msearch" ).click(function() {
  $( ".search" ).fadeIn( "fast", function() {

  });
});
</script>
    <script language="JavaScript" type="text/JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>


    <div id="db">


        <?php
    include('conn.php');    
    session_start();


    $_SESSION['byidaifa']= (isset($_REQUEST['byidaifa']) ) ? $_REQUEST['byidaifa'] : NULL;
    $_SESSION['bynome']=$_REQUEST ['bynome'];
    $_SESSION['bycognome']=$_REQUEST ['bycognome'];
    $_SESSION['bytipologia']=$_REQUEST ['bytipologia'];
    $_SESSION['bymarca']=$_REQUEST ['bymarca'];
    $_SESSION['bymodello']=$_REQUEST ['bymodello'];
    $_SESSION['byseriale']=$_REQUEST ['byseriale'];
    $_SESSION['bystato']=$_REQUEST ['bystato'];
    $_SESSION['bysoftware']=$_REQUEST ['bysoftware'];


    $limit = 50; 





    $count = "SELECT COUNT(*) as num FROM asset WHERE ID ";

    if(!empty($_REQUEST ['byidaifa']))
        $count = $count . " AND IDAIFA LIKE '".$_SESSION['byidaifa']."' ";

    if($_REQUEST ['bynome'])
        $count = $count . " AND Nome LIKE '".$_SESSION['bynome']."' ";  

    if($_REQUEST ['bycognome'])
        $count = $count . " AND Cognome LIKE '".$_SESSION['bycognome']."' ";    

    if($_REQUEST ['bytipologia'])
        $count = $count . " AND Tipologia LIKE '".$_SESSION['bytipologia']."' ";    

    if($_REQUEST ['bymarca'])
        $count = $count . " AND Marca LIKE '".$_SESSION['bymarca']."' ";    

    if($_REQUEST ['byseriale'])
        $count = $count . " AND Software LIKE '".$_SESSION['byseriale']."' ";   

    if($_REQUEST ['bymodello'])
        $count = $count . " AND Modello LIKE '".$_SESSION['bymodello']."' ";

    if($_REQUEST ['bystato'])
        $count = $count . " AND Stato LIKE '".$_SESSION['bystato']."' ";

    if($_REQUEST ['bysoftware'])
        $count = $count . " AND Software LIKE '".$_SESSION['bysoftware']."' ";              

        $resultcount = mysql_query($count);

        $total_pages = mysql_fetch_array(mysql_query($count));
        $total_pages = $total_pages['num'];

        $stages = 3;

    $page = isset($_GET['page']) ? mysql_real_escape_string($_GET['page']) : 0;
    if($page){
        $start = ($page - 1) * $limit; 
    }else{
        $start = 0; 
        }   

        $querysearch = "SELECT * FROM asset WHERE ID ";

    if(!empty($_REQUEST ['byidaifa']))
        $querysearch = $querysearch . " AND IDAIFA LIKE '".$_SESSION['byidaifa']."' ";

    if($_REQUEST ['bynome'])
        $querysearch = $querysearch . " AND Nome LIKE '".$_SESSION['bynome']."' ";  

    if($_REQUEST ['bycognome'])
        $querysearch = $querysearch . " AND Cognome LIKE '".$_SESSION['bycognome']."' ";    

    if($_REQUEST ['bytipologia'])
        $querysearch = $querysearch . " AND Tipologia LIKE '".$_SESSION['bytipologia']."' ";    

    if($_REQUEST ['bymarca'])
        $querysearch = $querysearch . " AND Marca LIKE '".$_SESSION['bymarca']."' ";    

    if($_REQUEST ['bymodello'])
        $querysearch = $querysearch . " AND Modello LIKE '".$_SESSION['bymodello']."' ";

    if($_REQUEST ['bystato'])
        $querysearch = $querysearch . " AND Stato LIKE '".$_SESSION['bystato']."' ";

    if($_REQUEST ['bysoftware']){
        $querysearch = $querysearch . " AND Software LIKE '".$_SESSION['bysoftware']."' ";  
        }
        $querysearch = $querysearch . " LIMIT $start, $limit ";

        $resultsearch = mysql_query($querysearch);

        if(isset($_REQUEST))
                             {
                               unset($_REQUEST['page']);
                               $querysearch = http_build_query($_REQUEST);
                             }

        // Initial page num setup
    if ($page == 0){$page = 1;}
    $prev = $page - 1;  
    $next = $page + 1;                          
    $lastpage = ceil($total_pages/$limit);      
    $LastPagem1 = $lastpage - 1;                    


    $paginate = '';
    if($lastpage > 1)
    {   




        $paginate .= "<div class='paginate'>";
        // Previous
        if ($page > 1){
            $paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=$prev'>Prev</a> ";
        }else{
            $paginate.= "<span class='disabled'>previous</span>";   }



        // Pages    
        if ($lastpage < 7 + ($stages * 2))
        {   
            for ($counter = 1; $counter <= $lastpage; $counter++)
            {
                if ($counter == $page){
                    $paginate.= "<span class='current'>$counter</span>";
                }else{
                    $paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=$counter'>$counter</a>";}                   
            }
        }
        elseif($lastpage > 5 + ($stages * 2))
        {

            if($page < 1 + ($stages * 2))       
            {
                for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
                {
                    if ($counter == $page){
                        $paginate.= "<span class='current'>$counter</span>";
                    }else{
                        $paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=$counter'>$counter</a>";}                   
                }
                $paginate.= "...";
                $paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=$LastPagem1'>$LastPagem1</a>";
                $paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=$lastpage'>$lastpage</a>";      
            }

            elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
            {
                $paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=1'>1</a>";
                $paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=2'>2</a>";
                $paginate.= "...";
                for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
                {
                    if ($counter == $page){
                        $paginate.= "<span class='current'>$counter</span>";
                    }else{
                        $paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=$counter'>$counter</a>";}                   
                }
                $paginate.= "...";
                $paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=$LastPagem1'>$LastPagem1</a>";
                $paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=$lastpage'>$lastpage</a>";      
            }

            else
            {
                $paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=1'>1</a>";
                $paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=2'>2</a>";
                $paginate.= "...";
                for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
                {
                    if ($counter == $page){
                        $paginate.= "<span class='current'>$counter</span>";
                    }else{
                        $paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=$counter'>$counter</a>";}                   
                }
            }
        }

                // Next
        if ($page < $counter - 1){ 
            $paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=$next'>next</a>";
        }else{
            $paginate.= "<span class='disabled'>next</span>";
            }

        $paginate.= "</div>";       


}
 echo $total_pages.' Results';
 // pagination


 echo "<table class='record' style='margin:0 auto;'>";

echo "<tr>",
"<td colspan='3'> Azioni </td> <td> Nome </td> <td> Cognome </td> <td> IDAIFA </td> <td> Utilizzo</td> <td> Tipologia</td> <td>Marca</td> <td>Modello</td> <td>Stato</td>",
"</tr> \n";

        if ($resultsearch)
        while($dati = mysql_fetch_assoc($resultsearch))
        {

        echo "<tr>";
echo "<td> <a href='#' onclick=\"MM_openBrWindow('detailasset.php?ID=$dati[ID]','nuovaFinestra','width=700,height=800,scrollbars=1,resizable=1')\"><img src='../images/eye.png'></a> </td>";
echo "<td> <a href='#' onclick=\"MM_openBrWindow('modasset.php?ID=$dati[ID]','nuovaFinestra','width=700,height=800,scrollbars=1,resizable=1')\"><img src='../images/edit.png'></a> </a> </td>";
echo "<td> <a href='deleteasset.php?ID=$dati[ID]?confirm=true' class='confirm'> <img src='../images/delete.png'></a></td>";

print "<td> $dati[Nome] </td>";
print "<td> $dati[Cognome] </td>";
print "<td> $dati[IDAIFA] </td>";
print "<td> $dati[Utilizzo] </td>";
print "<td> $dati[Tipologia] </td>";
print "<td> $dati[Marca] </td>";
print "<td> $dati[Modello] </td>";
print "<td> $dati[Stato] </td>";


echo "</tr> \n";

        }

    echo "</table></div>\n";
     echo $paginate;


    ?>

</div>
<script>
$(".confirm").easyconfirm({locale: {
        title: 'Elimina Asset',
        text: 'Vuoi eliminare questo Asset',
        button: ['No','Si'],
        closeText: 'Chiudi'
    }});
    $("#alert").click(function() {
    alert('Asset Cancellato');  
    });
</script>
    </body>
</html>
4

0 回答 0