Hm. I've got a database with exactly 100 entries in it.
I'm trying the following query:
$term is passed to the script from a CGI input field. The funny thing is, it's like the thing goes into a loop. I get something like 4,000+ results! And as I said, there's only 100 entries in the database.
When you're joining two tables (is that even what I'm doing here?) can't you use LIKE at all? It just seems to go into some infinite loop, or at least output all results a 1000 times.
Does anyone know what I'm doing wrong? For reference, here's my entire sub, if it helps anyone. Thank you!!
$term = $query->param('term');
$type = $query->param('type');
if ($type eq "All") {
$ifquery = "ata_offers.offer LIKE '%$term%'";
}
else {
$ifquery = "ata_offers.offer LIKE '%$term%' AND ata_members.type LIKE '%$type%'";
}
$dbh = $mysql->connect_to_db;
$numrec = $dbh->selectrow_array("SELECT COUNT(*) FROM ata_members,ata_offers WHERE $ifquery");
if ($numrec eq "0") {
&error_html("Sorry, no results found..<BR><BR>
Please try again or look through the full listing.");
exit;
}
$sth = $dbh->prepare("SELECT * FROM ata_members,ata_offers WHERE $ifquery");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref())
{
$offer_details .= qq|<tr bgcolor="#F4EFF7">
<td class="text-black" width="25%">$ref->{'name'}</td>
<td class="text-black" width="57%">$offer</td>
<td class="text-black" width="18%">$ref->{'offer_end'}</td>
</tr>
|; }
$sth->finish;
$dbh->disconnect;
&print_page("/offers/search.html");
}
- wil
I'm trying the following query:
Code:
$numrec = $dbh->selectrow_array("SELECT COUNT(*) FROM ata_members,ata_offers WHERE ata_offers.offer LIKE '%$term%'");$term is passed to the script from a CGI input field. The funny thing is, it's like the thing goes into a loop. I get something like 4,000+ results! And as I said, there's only 100 entries in the database.
When you're joining two tables (is that even what I'm doing here?) can't you use LIKE at all? It just seems to go into some infinite loop, or at least output all results a 1000 times.
Does anyone know what I'm doing wrong? For reference, here's my entire sub, if it helps anyone. Thank you!!
Code:
sub ata_off_sch { $term = $query->param('term');
$type = $query->param('type');
if ($type eq "All") {
$ifquery = "ata_offers.offer LIKE '%$term%'";
}
else {
$ifquery = "ata_offers.offer LIKE '%$term%' AND ata_members.type LIKE '%$type%'";
}
$dbh = $mysql->connect_to_db;
$numrec = $dbh->selectrow_array("SELECT COUNT(*) FROM ata_members,ata_offers WHERE $ifquery");
if ($numrec eq "0") {
&error_html("Sorry, no results found..<BR><BR>
Please try again or look through the full listing.");
exit;
}
$sth = $dbh->prepare("SELECT * FROM ata_members,ata_offers WHERE $ifquery");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref())
{
$offer_details .= qq|<tr bgcolor="#F4EFF7">
<td class="text-black" width="25%">$ref->{'name'}</td>
<td class="text-black" width="57%">$offer</td>
<td class="text-black" width="18%">$ref->{'offer_end'}</td>
</tr>
|; }
$sth->finish;
$dbh->disconnect;
&print_page("/offers/search.html");
}
- wil