Hi I need some help if possible please.. the script below uses a flat file database and prints an artists name and then the records listed for that artist, which is exactly what I want it to do..
However each time a new artist is added to the database I have to do a new for each statement.
Is there any way I can make it look for the artist from the $artist fields print that artists name then do a for each statement automatically so that I dont have to add one to the script manualy each time.
I think my way the script will also get very slow as the number of artists increases.. as you can probably guess Im not a perl programmer as much as a fiddler but I am trying to learn..
Thanks in advance
Rob
#!/usr/bin/perl
use CGI;
$req = new CGI;
$datadir = "/home/open(FILE,"$datadir/data.log"
@data = <FILE>;
close(FILE);
print "content-type:text/html\n\n";
$num = @data;
$result=0; $i=0; $j=0; $a=0;
foreach $data (@data) {
($id,$simage,$bimage,$artist,$ref,$size,$desc,$price,$title,$display) = split(/::/, $data);
if ($artist eq "Jean-Michel-Basquiat" {
$result++;
}
}
$page = $req->param('page');
if ($page eq '') { $page=0;}
else { $line = $page*100; }
if ($page ==0) {
#start asrtist
print "<br><br>Jean-Michel-Basquiat<br>";
print "<table cellpadding=0 cellspacing=0 width=100%>";
foreach $data (@data) {
($id,$simage,$bimage,$artist,$ref,$size,$desc,$price,$title,$display) = split(/::/, $data);
if ($artist eq "Jean-Michel-Basquiat" {
$i++;$j++;
if ($j <= 100) {
if ($i==1) {
print "<tr>";
}
print"<td width=30% align=center valign=top>";
print "<span class=\"menuleft\"><a class=\"cgilink\" href=\" print "</td>";
if ($i == 3) {
print "</tr><tr height=\"22\"></tr>";
$i = 0;
}
} # end j <=6
else { last;}
} # end if
} # end foreach
print "</table>";
print "<br><br>Pablo Picasso<br>";
print "<table cellpadding=0 cellspacing=0 width=100%>";
foreach $data (@data) {
($id,$simage,$bimage,$artist,$ref,$size,$desc,$price,$title,$display) = split(/::/, $data);
if ($artist eq "Pablo Picasso" {
$i++;$j++;
if ($j <= 100) {
if ($i==1) {
print "<tr>";
}
print"<td width=30% align=center valign=top>";
print "<span class=\"menuleft\"><a class=\"cgilink\" href=\" print "</td>";
if ($i == 3) {
print "</tr><tr height=\"22\"></tr>";
$i = 0;
}
} # end j <=6
else { last;}
} # end if
} # end foreach
print "</table>";
} # end else
However each time a new artist is added to the database I have to do a new for each statement.
Is there any way I can make it look for the artist from the $artist fields print that artists name then do a for each statement automatically so that I dont have to add one to the script manualy each time.
I think my way the script will also get very slow as the number of artists increases.. as you can probably guess Im not a perl programmer as much as a fiddler but I am trying to learn..
Thanks in advance
Rob
#!/usr/bin/perl
use CGI;
$req = new CGI;
$datadir = "/home/open(FILE,"$datadir/data.log"
@data = <FILE>;
close(FILE);
print "content-type:text/html\n\n";
$num = @data;
$result=0; $i=0; $j=0; $a=0;
foreach $data (@data) {
($id,$simage,$bimage,$artist,$ref,$size,$desc,$price,$title,$display) = split(/::/, $data);
if ($artist eq "Jean-Michel-Basquiat" {
$result++;
}
}
$page = $req->param('page');
if ($page eq '') { $page=0;}
else { $line = $page*100; }
if ($page ==0) {
#start asrtist
print "<br><br>Jean-Michel-Basquiat<br>";
print "<table cellpadding=0 cellspacing=0 width=100%>";
foreach $data (@data) {
($id,$simage,$bimage,$artist,$ref,$size,$desc,$price,$title,$display) = split(/::/, $data);
if ($artist eq "Jean-Michel-Basquiat" {
$i++;$j++;
if ($j <= 100) {
if ($i==1) {
print "<tr>";
}
print"<td width=30% align=center valign=top>";
print "<span class=\"menuleft\"><a class=\"cgilink\" href=\" print "</td>";
if ($i == 3) {
print "</tr><tr height=\"22\"></tr>";
$i = 0;
}
} # end j <=6
else { last;}
} # end if
} # end foreach
print "</table>";
print "<br><br>Pablo Picasso<br>";
print "<table cellpadding=0 cellspacing=0 width=100%>";
foreach $data (@data) {
($id,$simage,$bimage,$artist,$ref,$size,$desc,$price,$title,$display) = split(/::/, $data);
if ($artist eq "Pablo Picasso" {
$i++;$j++;
if ($j <= 100) {
if ($i==1) {
print "<tr>";
}
print"<td width=30% align=center valign=top>";
print "<span class=\"menuleft\"><a class=\"cgilink\" href=\" print "</td>";
if ($i == 3) {
print "</tr><tr height=\"22\"></tr>";
$i = 0;
}
} # end j <=6
else { last;}
} # end if
} # end foreach
print "</table>";
} # end else