Hi, I've got a script that grab a variable from the url and outputs the appropriate info from a text file (I've got no real database access) and displays a default menu if the variable isn't present. My problem is that I have to add a few more text files (representing different products lines) into the mix and I'm not sure how to do this based on what I've got.
Here's what I've got working right now for one text file (one product line):
<?php
// TEXT DB FIELDS
// [0] key
// [1] url name
// [2] product name
// [3] main image file name (275x275)
// [4] sub-image 1 (130x130)
// [5] sub-image 2 "
// [6] sub-image 3 "
// [7] sub-image 4 "
// [8] product description (xhtml)
// grab product line ($line) from url
$line=$_GET['line'];
// read the product file from the product files directory
$file_content = file('products/products_hd.php');
// if there is a product line ($line) in the url, show product description
if(!empty($line)) {
// loop the contents of the product file
foreach($file_content as $data) {
$field = explode("|" , $data);
if(trim($field[1]) == $line ) {
// parse the array elements into the template
echo "<h3>".$field[2]."</h3>
<p><img src=\"images/".$field[3]."\" alt=\"".$field[2]."\" align=\"left\" style=\"padding: 0 8px 8px 0;\" />".$field[8]."
<h4>Additional Photos</h4>
<div class=\"product_thumbs\">";
// if additional image fields are not empty, show images
if(!empty($field[4])) {
echo "<img src=\"images/".$field[4]."\" alt=\"secondary image\" width=\"130\" height=\"130\" /> "; }
if(!empty($field[5])) {
echo "<img src=\"images/".$field[5]."\" alt=\"secondary image\" width=\"130\" height=\"130\" /> "; }
if(!empty($field[6])) {
echo "<img src=\"images/".$field[6]."\" alt=\"secondary image\" width=\"130\" height=\"130\" /> "; }
if(!empty($field[7])) {
echo "<img src=\"images/".$field[7]."\" alt=\"secondary image\" width=\"130\" height=\"130\" /> "; }
echo "</div>
<p style=\"border-top:1px dotted #ccc;clear:both;\" class=\"reset_bottom\"><a href=\"products.php?prod=blinds\">« back to blinds</a></p>";
}
}
// if a product line ($line) is not present in the url
} else {
// show default menu list
echo "\t\t\t<div id=\"blinds_hd\">
<h3 class=\"clear_left\"><br />Hunter Douglas Window Blinds</h3>
<ul class=\"blinds_list\">\n";
// loop the data, and add css class to every second list element
foreach($file_content as $data) {
$field = explode("|" , $data);
$i++;
$class = ($i %2 == 0) ? 'right' : '';
echo "\t\t\t\t<li class=\"".$class."\"><p><a href=\"".$PHP_SELF."?prod=blinds&line=".$field[1]."\">".$field[2]."</a><br />\n";
echo "\t\t\t\t<a href=\"".$PHP_SELF."?prod=blinds&line=".$field[1]."\"><img src=\"images/".$field[3]."\" alt=\"".$field[2]."\" /></a></p></li>\n";
}
echo "\t\t</ul>
<br />
</div> <!-- end of #blind_hd -->\n";
}
?>
Thanks in advance for any help. I just don't understand the PHP manual half the time and I'm totally not a programmer so please be gentle 🙂