I am doing a product sheet database web application for my client.
In the database I have a product number and its name.
All the products have extarnal files asociated (pdf,doc, etc.)
These files exists on the filesystem.
The files strings is build with the product number.
eg.
095137 has these files:
AS095137.pdf, FD095137.pdf etc
There are 5 files for each product, eg.
AS,FD,HG,TY,RT
The tricky part is that this is all I know. So I came up with this solution
Loop through the database
Inside this loop open the file directory
read the files and do a match.
if match is true, print the file.
See code:
foreach($getDocs as $getDocs) {
//Open file catalogue.
$dir = @opendir("../docweb/");
if ($cssClass == "dataA") {
$cssClass = "dataB";
}
else {
$cssClass = "dataA";
}
//Place data in HTML table cells.
echo "<tr>\n";
echo "<td class=\"".$cssClass."\">".$getDocs->partno."</td>\n";
echo "<td class=\"".$cssClass."\">".$getDocs->partname."</td>\n";
echo "<td class=\"".$cssClass."\">";
//Reads the files in the catalogue.
while (($file = readdir($dir)) !== false) {
//Finds needle in the haystack. and print the files I find
if (strstr($file,$getDocs->partno)) {
echo "<a href=\"http://localhost/publis/docweb/".$file."\" target=\"_blank\">".$file."</a><br>\n";
}
else {
}
}
echo "</td>\n";
echo "</tr>\n";
closedir($dir);
}
Is there an easier way to do this?
regards Thomas A: