At 15:40 -0800 1/19/03, Melissa Stranzl wrote:
I am trying to get my program to be searchable by
date, but it doesn't work.  I get an error message in
perl, that follows the code I included.  Any
suggestions are greatly appreciated.

PERL
----------
@currenttime= localtime();

$y= $currenttime [5] + 1900;

$m= $currenttime [4];
$dom= $currenttime [3];

$ydoy= $y*1000 + $m + $dom;
print $ydoy;

my $dbh= DBI->connect ('DBI:mysqlPP:myd:localhost',
'pass', 'pass') ||die "Could not connect to database:
".DBI->errstr;
my $sth = $dbh->prepare("SELECT * from food WHERE
end_date > $ydoy");
$sth->execute($ydoy);
Wouldn't it be simpler to skip all that date manipulation stuff and
simply write your query like this?

SELECT * from food WHERE end_date > CURDATE()


while((end_date > $ydoy) = $sth->fetchrow_array)
That's illegal, because you're trying to assign a value to an
expression.  Also, "end_date" is a bareword.  Anyway, doesn't
your query already rule out records where the end_date values
are not greater than the current date?  So you should be able
to just write this as:

while (($start_date, $end_date, $event) = $sth->fetchrow_array)

(I'm assuming that SELECT * returns rows in start_date, end_date, event
column order, which may be incorrect.  If you're retrieving arrays,
you *REALLY* should name the columns explicitly in the order you want
in the SELECT statement, and *NOT* use SELECT *, which guarantees nothing
about column order in the result set.)

{
print "$start_date\n, $end_date\n, $event\n, $id";
}

die $sth->errstr if $sth->err;


$sth->finish();
$dbh->disconnect();

ERROR MESSAGE:
--------------

can't modify generic gt()) in list assignment at line
31 (which is the fetchrow_array line)
repeated HERE:
while((end_date > $ydoy) = $sth->fetchrow_array)
{
print "$start_date\n, $end_date\n, $event\n, $id";
}


Thanks again for your help.

Melissa Stranzl

917-922-7872

---------------------------------------------------------------------
Before posting, please check:
  http://www.mysql.com/manual.php   (the manual)
  http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to