I am currenlty building blog with expressionengine. i want to display how long the entries have published.
How can i get how long hours/day ago channel entries published?
Thanks
I have solved this problem,
in my template, i allow PHP
then i add this code that i found from http://css-tricks.com/snippets/php/time-ago-function/
but don't use function, i don't know but it gives me error. just straight to the main
like this:
<?php
$time = strtotime("{entry_date format="%d %F %Y"}");
$periods = array("Second", "Minute", "Hour", "Day", "Week", "Month", "Year", "Decade");
$lengths = array("60","60","24","7","4.35","12","10");
$now = time();
$difference = $now - $time;
$tense = "ago";
for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
if($difference != 1) {
$periods[$j].= "s";
}
echo "$difference $periods[$j] Ago";
?>
may help another that having the same problem as i am
Related
i fetch the date from database and I want to get days between now date & and that date
public function getdata(request $request)
{
$stuId = $request->input('stId');
$data = Student_barrow::where('User_Id', "$stuId")->get();
foreach($data as $item){
$date = Carbon::parse($item);
$now = Carbon::now()->format('Y-m-d');
$diff = $date->diffInDays($now);
return $diff;
}
}
I am using PHP Mailer.
I want to add dynamic content in php to the body but I am not being able to do it.
If I add this on the php mailer body, it works.
$mail->Body="<h3>Dados do 1º Titular</h3><ul><li><b>Nome: </b>".$titular1_name."</li><li><b>Idade: </b>".$titular1_idade."</li><li><b>Estado Civil</b>".$titular1_estado_civil."</li><li><b>Dependentes</b>".$titular1_dependentes."</li><li><b>Rendimento</b>".$titular1_rendimento."</li><li><b>Penhora</b>".$titular1_penhora."</li></ul><h3>Dados do 2º titular</h3><ul><li><b>Nome: </b>".$titular2_name."</li><li><b>Idade: </b>".$titular2_idade."</li><li><b>Estado Civil</b>".$titular2_estado_civil."</li><li><b>Dependentes</b>".$titular2_dependentes."</li><li><b>Rendimento</b>".$titular2_rendimento."</li><li><b>Penhora</b>".$titular2_penhora."</li></ul><h3>Dados de Contacto</h3><ul><li><b>Email: </b>".$titular_email."</li><li><b>Telefone</b>".$titular_phone."</li><li><b>Localidade</b>".$titular_local."</li></ul>";
But I need to add this result:
for ($y = 0; $y <= $numberOfRows; $y++){
for ($x = 0; $x < $maxData; $x++) {
array_push($row, $credito,
$capital_divida, $prestacao,
$bank, $garantias, $situacao);
echo $row[$x]."<br>";
}
array_push($fullData, $row);
}
This is my relevant code for this issue:
$row = array();
$fullData = array();
$maxData = 6;
$numberOfRows = htmlspecialchars(["numberOfRowsHTML"]);
$titular_email = htmlspecialchars($_POST["titular-email"]);
$titular_phone = htmlspecialchars($_POST["titular-phone"]);
$titular_local = htmlspecialchars($_POST["titular-local"]);
$titular_message = htmlspecialchars($_POST["titular-message"]);
$numberOfRows = htmlspecialchars(["numberOfRowsHTML"]);
$credito = htmlspecialchars(["credito"]);
$capital_divida = htmlspecialchars(["capital_div"]);
$prestacao = htmlspecialchars(["prestacao"]);
$bank = htmlspecialchars(["bank"]);
$garantias = htmlspecialchars(["garantias"]);
$situacao = htmlspecialchars(["situacao"]);
Thank you in advance for all the help
This code doesn't make any sense:
$numberOfRows = htmlspecialchars(["numberOfRowsHTML"]);
It looks like you're missing the name of an array you want to get this value from, for example:
$numberOfRows = htmlspecialchars($_POST["numberOfRowsHTML"]);
Your loop that assembles the array doesn't appear to do anything useful at all - you're getting values from the submission, then assembling an array which you don't use. It would be helpful if you could clarify what it is you're trying to do.
I am writing a program to parse an .xls file. For that I have a template which contains five merged cells (B1,C1,D1,E1,F1) and written "User-Dependent errors" in that. In B2,C2,D2,E2,F2 I have written the error names and want to save their count every day. The code is working properly but after parsing and saving the merged cell (B1,C1,D1,E1,F1) is getting unmerged and the text is presented in B1. I need the merged cells as is (merged), even after parsing.
What do I have to do?
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::SaveParser;
my $date=$ARGV[1]; #yymmdd
my $hour=$ARGV[0]; #06
$date or $date=`date --date='1 day ago' +%Y%m%d`;
chomp $date;
chomp $hour;
my $db_name = "ravi";
my $table = "CDR";
my $sub_table = "Submission_Failures";
my $del_table = "Delivery_Failures";
my $host = "xxx.xx.x.xxx";
my $command = "cp /root/prac/CDR/CDR.xls /root/prac/CDR/CDR_Report_20$date$hour.xls";
print $command;
`$command`;
sub NULL_count
{
my $type = $_[0];
my #temp_array;
my $error_db = DBI->connect("DBI:mysql:database=$db_name;host=$host;mysql_socket=/opt/lampstack-5.5.27-0/mysql/tmp/mysql.sock","root","", {'RaiseError' => 1});
my $error_sth = $error_db->prepare("SELECT Error_list from error_potrait WHERE Date='$date' and Type='$type'");
$error_sth->execute() or die $DBI::errstr;
while (my $temp = $error_sth->fetchrow_array())
{
push(#temp_array, $temp);
}
my $temp = #temp_array;
foreach my $i ($temp .. 4)
{
$temp_array[$i] = "NULL";
}
$error_sth->finish();
return #temp_array;
}
my #db_system_errors = NULL_count ("Submission_user_error");
my #db_network_errors = NULL_count ("Submission_ESME_error");
my #db_ESME_errors = NULL_count ("Submission_system_error");
my #db_user_errors = NULL_count ("Submission_network_error");
my #del_user_errors = NULL_count ("Delivery_user_error");
my #del_network_errors = NULL_count ("Delivery_network_error");
my #del_system_errors = NULL_count ("Delivery_system_error");
my #submission_errors = (#db_network_errors,#db_system_errors,#db_ESME_errors,#db_user_errors);
my #delivery_errors = (#del_user_errors,#del_network_errors,#del_system_errors);
sub error_headers
{
my $sheet_no = shift;
my #array = #_;
my $row = 1;
my $col = 1;
# Open an existing file with SaveParser
my $parser = Spreadsheet::ParseExcel::SaveParser->new();
my $template = $parser->Parse("CDR_Report_20$date$hour.xls") or die "Cant open xls";
# Get the first worksheet.
my $sheet = $template->worksheet($sheet_no);
$sheet->AddCell( 1, 0, $date );
foreach my $value (#array)
{
$sheet->AddCell( $row, $col, $value );
++$col;
}
$template->SaveAs("CDR_Report_20$date$hour.xls");
}
error_headers (3,#submission_errors);
error_headers (4,#delivery_errors);
sub parser_excel
{
my $sql_comm = $_[0];
my $sheet_no = $_[1];
my $row = $_[2];
my $col = $_[3];
my $dbh = DBI->connect("DBI:mysql:database=$db_name;host=$host;mysql_socket=/opt/lampstack-5.5.27-0/mysql/tmp/mysql.sock","root","", {'RaiseError' => 1});
#Selecting the data to fetch
my $sth = $dbh->prepare("$sql_comm");
$sth->execute() or die $DBI::errstr;
# Open an existing file with SaveParser
my $parser = Spreadsheet::ParseExcel::SaveParser->new();
my $template = $parser->Parse("CDR_Report_20$date$hour.xls") or die "Cant open xls";
# Get the first worksheet.
my $sheet = $template->worksheet($sheet_no);
$sheet->AddCell( $_[4], 0, $date );
while (my #row = $sth->fetchrow_array())
{
my $Date_db = shift #row;
foreach my $value (#row)
{
$sheet->AddCell( $row, $col, $value );
++$col;
}
$row++;
$col=0;
}
$template->SaveAs("CDR_Report_20$date$hour.xls");
$sth->finish();
}
parser_excel("Select * from $table where Date = $date and Hour = $hour",2,1,0,0);
parser_excel("Select * from $sub_table where Date = $date and Hour = $hour",3,2,0,1);
parser_excel("Select * from $del_table where Date = $date and Hour = $hour",4,2,0,1);`
The docs for Spreadsheet::ParseExcel::SaveParser state that the module works "by reading it with Spreadsheet::ParseExcel and rewriting it with Spreadsheet::WriteExcel". So any merged cells will be lost when re-writing. You will need to use the WriteExcel module to re-create the merged cells, which means you will have to separate the reading and writing in your own script.
To merge the cells you use the "merge_range" method with a Format:
my $format = $workbook->add_format( align => 'left' );
$worksheet->merge_range('B1:F1', 'User-Dependent errors', $format);
See the docs for Spreadsheet::WriteExcel
I was using Spreadsheet::WriteExcel to create xls file using perl. When the range of spreadsheet increased, the Microsoft excel shows an alert before opening the file "File Error: Data may have been lost".
Please help me to solve this.
Here is the code
my $row = 2;
foreach my $sid(array of students objects)
{
my $s = $students->{$sid};
my $cc = 0;
my $wall = f1($x, $y, $z);#f1 is a method returns hash of arrays that have to write on excel having keys #key_array
foreach my $key (#key_array) {
my $t_row = $row;
my $i_c = 0;
my $t_col = 0;
my $m_row = $max_row;
while($m_row > 0){
$t_col = 3+($cc*7);
if($cc == 0){
$ws->write($t_row, 0,
[$s->{first_name}, $s->{last_name}, $s->{l_name}], $fmt_wrap
);
}
if(defined $wall->{$key}->[$i_c] ){
$ws->write($t_row, $t_col, $wall->{$key}->[$i_c], $fmt_wrap);
} else {
$ws->write($t_row, (3+$cc*7),["","","","","","",""], $fmt_wrap);
}
$t_row++;
$i_c++;
$m_row--;
}#while loop
$ws->write($t_row-1, 3+$company_format*$max_step,
[ (scalar keys %{$s->{videos}}), $s->{total_pageviews} ], $fmt
);
$cc++;
$t_row = 2;
}#foreach loop
$row+=$max_row;
}#foreach student array
I have found answer. In the code there was a line which write data into a cell multiple times. So i found that multiple write attempt to a particular cell can cause file corruption.
I'm new to perl. I have two excel files containing huge no of rows and just two columns. I want to get each cell from one of the excel files and search whether its there in another excel file or not. if its not then print that cell.
I believe that if I get each cell from one of the excel and search it in another and then run a for loop for all the rows it will be done.
I reached upto getting the cell from first excel but how to search whether it is there in the another excel and printing it is the issue.
can anybody help. ??
I'm not entirely sure what you want, but this might give you some ideas. It's completely untested, though.
use strict;
use Spreadsheet::ParseExcel;
my $parser = Spreadsheet::ParseExcel->new();
my $workbook1 = $parser->parse('Book1.xls');
if (!defined $workbook1) { die $parser->error(), ".\n"; }
my $workbook2 = $parser->parse('Book2.xls');
if (!defined $workbook2) { die $parser->error(), ".\n"; }
$worksheet1 = $workbook1->worksheet('Sheet1');
$worksheet2 = $workbook2->worksheet('Sheet1');
my ($row_min1, $row_max1) = $worksheet1->row_range();
my ($col_min1, $col_max1) = $worksheet1->col_range();
for my $row1 ($row_min1 .. $row_max1) {
for my $col1 ($col_min1 .. $col_max1) {
my $cell1 = $worksheet1->get_cell($row1, $col1);
my ($row_min2, $row_max2) = $worksheet2->row_range();
my ($col_min2, $col_max2) = $worksheet2->col_range();
my $found_match = 0;
for my $row2 ($row_min2 .. $row_max2) {
for my $col2 ($col_min2 .. $col_max2) {
my $cell2 = $worksheet2->get_cell($row2, $col2);
if ($cell1->value() eq $cell2->value()) { # or == ?
$found_match = 1;
break;
}
}
break if $found_match;
}
if (!$found_match) {
print $cell1->value, "\n";
}
}
}
This is mostly from here: http://search.cpan.org/dist/Spreadsheet-ParseExcel/lib/Spreadsheet/ParseExcel.pm