Gossamer Forum
Home : General : Perl Programming :

Re: [lanerj] SQL Query problem

Quote Reply
Re: [lanerj] SQL Query problem In reply to
Thanks for your help, Bob! I've never used joins before, and I'm pleased I've just started :-). This is the final code I used, which works perfectly. Thanks.

Code:
sub generate_offer_index {

$dbh = $mysql->connect_to_db;

$numrec = $dbh->selectrow_array("SELECT COUNT(*) FROM ata_offers");

my $query = qq|SELECT M.name, O.offer_start, O.offer_end, O.offer, O.icon, O.additional FROM ata_members AS M, ata_offers AS O WHERE M.id=O.id|;
$sth = $dbh->prepare($query);
$sth->execute or die("Can't execute SQL query:<BR><BR>[$DBI::err] $DBI::errstr");

while (my $ref = $sth->fetchrow_hashref())
{

$offer_data .= qq|<tr bgcolor="#F4EFF7">
<td class="text-black" width="25%">$ref->{'name'}</td>
<td class="text-black" width="57%">$ref->{'offer'}</td>
<td class="text-black" width="18%">$ref->{'offer_end'}</td>
</tr>
|;
}

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

}

- wil
Subject Author Views Date
Thread SQL Query problem Wil 5314 Jan 18, 2002, 10:17 AM
Thread Re: [japh] SQL Query problem
Paul 5155 Jan 18, 2002, 10:30 AM
Thread Re: [RedRum] SQL Query problem
Wil 5162 Jan 18, 2002, 10:34 AM
Thread Re: [japh] SQL Query problem
Wil 5168 Jan 18, 2002, 10:37 AM
Thread Re: [japh] SQL Query problem
lanerj 5153 Jan 19, 2002, 2:01 AM
Thread Re: [lanerj] SQL Query problem
Wil 5140 Jan 19, 2002, 10:14 AM
Thread Re: [japh] SQL Query problem
lanerj 5100 Jan 19, 2002, 8:31 PM
Thread Re: [lanerj] SQL Query problem
lanerj 5122 Jan 20, 2002, 1:47 AM
Post Re: [lanerj] SQL Query problem
Wil 5089 Jan 21, 2002, 4:12 AM