stonecolddevin has asked for the wisdom of the Perl Monks concerning the following question:
## index.cgi #!perl -w use strict; use PL; my $obj = PL->new; my @info = $obj->DBI->Entries->retrieve_from_sql(qq{ hidden = "n" ORDER BY date desc LIMIT 5 }); my %data; my @loop_data = (); ## NOT INCREMENTING PRIMARY KEY, THUS RETURNING THE FIRST ROW *TWICE* for (@info) { $data{author} = $_->author; $data{content} = $_->content; $data{title} = $_->title; $data{id} = $_->id; $data{date} = $_->date; push @loop_data, \%data; } my %content = ( title=>'Devin\'s Journal v.9', body=>\@loop_data, # CRITICAL: must + be arrayref containing hashref, # DBI should be $s +th->fetchrow_arrayref({}); search=>'search?q=', #to be defined in +Config.pm referer => $ENV{'REFERER'} ? $ENV{'REFERER'} : "none", IPAddy => $ENV{'REMOTE_ADDR'} ); $obj->Template->file ("tmpl/main.tmpl"); print $obj->Template->format ( \%content ); ## PL::DBI::Entries.pm package PL::DBI::Entries; use strict; use base 'PL::DBI'; sub new { my $class = shift; my $self = {}; bless $self, $class; return $self; } __PACKAGE__->columns( Primary => qw[id] ); __PACKAGE__->columns( All => qw [ id author title date content ip ] ); __PACKAGE__->table('entries'); 1;
janitored by ybiC: Retitle from "Class::DBI" because one-word-node-titles hinder site search
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Duplicate rows with Class::DBI
by friedo (Prior) on Apr 25, 2005 at 23:09 UTC | |
by stonecolddevin (Parson) on Apr 25, 2005 at 23:13 UTC | |
by eibwen (Friar) on Apr 26, 2005 at 00:37 UTC | |
by friedo (Prior) on Apr 26, 2005 at 02:53 UTC |