From the code below I get the following errors:
Global symbol $start requires explicit package name.
I have already initialised this variable here,
but it refers to my SQL statement:
Am I not setting up this statement correctly?
All code is below:
Global symbol $start requires explicit package name.
I have already initialised this variable here,
Code:
my $start=$newLine[0];
but it refers to my SQL statement:
Code:
my ($queryAll) = " select ev_title, ev_locn, dateTime, dateTimeFin from calendar where dateTime > $start and dateTimeFin < $fin ;";
Am I not setting up this statement correctly?
All code is below:
Code:
#! c:/perl/bin/perl
use Mysql;
use strict;
use Spreadsheet::WriteExcel;
# HTTP HEADER
my ($host) = "localhost";
my ($database) = "joStark";
my ($tablename) = "calendar";
my ($user) = "root";
my ($pw) = "michael";
#dates from the php form
open FILE, "../export/dates.txt" or die "Cannot open file";
#assign them to variables
while (my ($line)=<FILE>)
{
my(@newLine)= split(/,/,$line);
my ($start)=$newLine[0];
my ($fin)=$newLine[1];
}
my $workbook = Spreadsheet::WriteExcel->new("perl.xls");
# Add some worksheets
my $sheet1 = $workbook->add_worksheet("Audit");
my $sheet2 = $workbook->add_worksheet("All Meetings");
my $format = $workbook->add_format();
my $format2 = $workbook->add_format();
#Add format
$format->set_bold();
$format->set_align('center');
# PERL MYSQL CONNECT
my ($connect) = Mysql->connect($host, $database, $user, $pw);
$connect->selectdb($database);
my ($queryAll) = " select ev_title, ev_locn, dateTime, dateTimeFin from calendar where dateTime > $start and dateTimeFin < $fin ;";
my ($executeAll)=$connect->query($queryAll);
my ($rowNumberAll) = $executeAll->numrows();
my ($numfieldsAll)= $executeAll->numfields();
my ($i)=3;
$sheet2->write(1, 0, "Meeting Title", $format);
$sheet2->write(1, 1, "Meeting Location", $format);
$sheet2->write(1, 2, "Date & Time Start", $format);
$sheet2->write(1, 3, "Date & Time Finish", $format);
my $dateformat = $workbook->add_format(num_format => 'dd/mm/yy H:mm AM/PM');
$sheet2->add_write_handler(qr/^\d{4}-\d{2}-\d{2}$/, \&write_date);
my ($min)=0;
for ($min=0;$min<=$numfieldsAll;$min++)
{
$sheet2->set_column($min,$min, 30);
}
while (my (@resultsAll) = $executeAll->fetchrow())
{
$sheet2->write($i, 0, $resultsAll[0]);
$sheet2->write($i, 1, $resultsAll[1]);
$sheet2->write($i, 2, $resultsAll[2], $dateformat);
$sheet2->write($i, 3, $resultsAll[3], $dateformat);
$i++;
}
#Query time!
my ($query) = " select ev_locn, sum(mtg_hrs) as total_hrs from ( select time_to_sec(timediff(dateTimeFin, dateTime)) / 3600.0 as mtg_hrs, ev_locn from calendar ) as t where mtg_hrs>=2.0 group by ev_locn;";
my ($execute)=$connect->query($query);
my ($rownumber) = $execute->numrows();
# FETCHROW ARRAY
#foreach (my (@results)=$execute->fetchrow())
while (my (@results) = $execute->fetchrow())
{
$sheet1->write(0, $i, $results[0], $format);
$sheet1->write(1, $i, $results[1]);
# print $i;
$i++;
}