Re: Using DBI, better option than importing into @array
- From: usenet@xxxxxxxxxxxxxxx
- Date: Tue, 31 Jul 2007 18:38:41 -0000
On Jul 30, 4:34 pm, Jason <jwcarl...@xxxxxxxxx> wrote:
the subjects table is
Categories: id - lastmodified - subject
Actual row: 17090 - 20070730192222 - This is a test
The posts table would be like:
Categories: id - subject - postdate - username - email - comment
Actual row: 17090 - This is a test - 20070730192222 - Jason -
jwcarl...@xxxxxxxxx - This is a test comment.
OK, try something like this (untested - I don't have a sample
database):
my $sth = $dbh->prepare(<<SQL);
select $forum_posts.id,
$forum_posts.subject,
$forum_posts.postdate,
$forum_posts.username,
$forum_posts.email,
$forum_posts.comment
from $forum_posts
left join id on ($forum_subjects.id = $forum_posts.id)
order by $forum_subjects.postdate ASC
limit 20
SQL
$sth->execute;
while (my $row = $sth->fetchrow_arrayref()) {
#do stuff
}
In retrospect, I can't quite remember why I'm duplicating the
information into the subjects table; I think it was at the suggestion
of someone in another NG.
The person who made such a suggestion is a complete idiot.
Would it be better to get rid of the "subjects" table altogether, and
just create an index with the ID field?
Absolutely.
counter for a few other things, too, though; in this case, I use it to
determine the background color of the table row (it alternates based
on whether $count is divisible by 2).
You don't need a counter to implement a simple boolean toggle;
something like this will do:
$toggle = ! $toggle;
my $color = ($toggle) ? $color1 : $color2;
But hopefully you are using a good template module (I prefer
HTML::Template) and CSS to drive your markup.
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
.
- References:
- Prev by Date: CGI displays contents of script
- Next by Date: Re: CGI displays contents of script
- Previous by thread: Re: Using DBI, better option than importing into @array
- Next by thread: Re: Using DBI, better option than importing into @array
- Index(es):
Relevant Pages
|