Good morning everyone.

I wonder, how can I do a search by date in a unix timestamp data, I will send my code below, thanks!

#!C:\wamp\bin\perl\bin\perl.exe BEGIN { use CGI::Carp "fatalsToBrowser"; } use CGI qw(param); use DBI; use warnings; use strict; my $porpagina = param('porpagina'); print "Content-type: text/html \n\n"; print <<END <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Transitional//EN" "http:/ +/www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Netdeep Secure</title> </head> END ; # Criei um objeto CGI my $cgi = CGI->new; # Carreguei o post numa variável e coloquei no sql das 2 consultas my $var = $cgi->param("nome"); if (!$porpagina) { $porpagina = 150; } # Conexão com o BD my $dbh = DBI->connect('DBI:mysql:messenger;host=localhost', 'root', ' +' ) || die "Could not connect to database: $DBI::errstr"; # Faz uma segunda consulta no banco para obter os dados do registro my $sth = $dbh->prepare("SELECT FROM_UNIXTIME(timestamp, '%d/%m/%Y - % +H:%i'), clientaddress, localid, remoteid, CONVERT(eventdata USING utf +8) FROM messages WHERE localid LIKE '%$var%' ORDER BY id DESC LIMIT $ +porpagina"); $sth->execute( ); $sth->{LongReadLen}=500000; $sth->{LongTruncOk}=1; print qq| <script type="text/javascript"> function somente_numeros(porpagina){ var campo = document.getElementById(porpagina).value; var divide = campo.split(""); var quant = divide.length; var permitidas = new Array (1,2,3,4,5,6,7,8,9,0); var i, achou = 0; var text = ''; for(i=0; i<10; i++){ if(divide[quant - 1] == permitidas[i]){ achou = 1; } } if(achou == 0){ divide[quant - 1] = ''; } for(i=0; i<quant; i++){ text += divide[i]; } document.getElementById(porpagina).value = text; } function enviar(){ var campo = document.getElementById('nome').value; if( campo != ''){ document.forms["pesquisa"].submit(); }else{ alert('O campo E-mail não pode ser vazio'); } } </script> |; print <<END <body> <div style="width:960px; height:30px; background:#dbdbdb;"> <h2 style="padding-left:15px;">Pesquisa</h2> </div> <br> <form action="script.cgi" method="post" name="pesquisa" id="pesquisa" +enctype="multipart/form-data"> E-mail: <input name="nome" id="nome" type="text" size="30" style="margin-left: +86px;" /> ex: contato\@empresa.com.br <br><br> Qtde. de registros: <input type="text" name="porpagina" id="porpagina" size="5" style="mar +gin-left:17px;" onkeyup="somente_numeros('porpagina')"> somente números <br><br> <input type="button" value="Buscar" onclick="enviar()" /> <input name="limpar" type="reset" value="Limpar" /> </form> <br> <div style="width:960px; height:30px; background:#dbdbdb;"> <h2 style="padding-left:15px;">Log</h2> </div> <table width="960"> <tr> <th scope="col" width="15%">Data - Hora</th> <th scope="col" width="13%">Endereço IP</th> <th scope="col" width="23%">De</th> <th scope="col" width="25%">Para</th> <th scope="col" width="24%">Mensagem</th> </tr> END ; while ( my($timestamp, $clientaddress, $localid, $remoteid, $eventdata +) = $sth->fetchrow_array() ) { print " <tr> <td align='center'>$timestamp</td> <td align='center'>$clientaddress</td> <td align='center'>$localid</td> <td align='center'>$remoteid</td> <td align='center'>$eventdata</td> </tr>".""; } print <<END </table> <div style="width:960px; height:30px; background:#dbdbdb;"> </div> END ; print <<END </body> </html> END ; $sth->finish(); $dbh->disconnect; undef $dbh;

In reply to Create a search by date in a unix timestamp data by maicon1121

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.