Hi all
I’m building a boat brokerage website. Each boat has its information stored in a flat .txt file in the format ENGINE=foo, PRICE=bar, DESCRIPTION=lorem, etc. Each boat has its own text file. The main page page should count the number of text files (boats), and then enter a loop to draw up a table for each boat (text file) and populate it with the information from the file (engine, etc.)
So far, this works great on the ‘details’ page where it is only pulling info from one file and populating that page. The problem comes on the index page where I want it to pull some summary info from EVERY text file. I don’t know what’s going wrong but if someone could help me, I’d be eternally grateful!
I currently have just two text files there for testing purposes.
The page itself is at: [url]http://www.broadsboatsales.co.uk/beta/motorboats
And the code is:
[CODE] <?php
if(!function_exists(‘get_value_of’));
function get_value_of($name) {
// by this point, it’s forgotten the value for
// $filename and returns null so doesn’t display anything
$lines = file(‘products/’ . $boatfile);
foreach (array_values($lines) AS $line) {
list($key, $val) = explode(‘=’, trim($line) );
if (trim($key) == $name) {
return $val; } }
return false; }
$directory = “products/”;
//get all text files with a .txt extension.
$textfiles = glob(“” . $directory . “*.txt”);
//print each file name
foreach($textfiles as $textfile)
{
$boatfile = substr($textfile, 9);
// $boatfile = $textfile;
// read the correct text file for first boat
// draw each table and insert data from appropriate text file using boatfile as reference
// a line to test it’s getting the right file (which it is)
echo(“Backend filename: ” . $boatfile);
// draw the table and populate it with the info from the function above
print(‘<table width=”100%” cellspacing=”0″ cellpadding=”3″ class=”products”><tr><td width=”85%” align=”left” bgcolor=”#FFFFCC” class=”producttitle”> ’ . get_value_of(‘LONGTITLE’) . ‘</td><td width=”15%” align=”right” bgcolor=”#FFFFCC” class=”productprice”>£’ . get_value_of(‘PRICE’) . ‘</td></tr><tr><td colspan=”2″><table width=”100%” border=”0″ cellspacing=”6″ cellpadding=”0″><tr><td width=”245″ align=”center” valign=”middle”><img src=”products/’ . get_value_of(‘FOLDER’) . ‘thumb.JPG” width=”245″ height=”163″ /></td><td align=”left” valign=”top”><table width=”100%” border=”0″ cellspacing=”6″ cellpadding=”0″><tr><td colspan=”2″ class=”productdescription”>’ . get_value_of(‘EXTRACT’) . ‘</td></tr><tr><td height=”1″ colspan=”2″ bgcolor=”#999999″></td></tr><tr><td width=”27%” valign=”middle” class=”productspecshdr”> <a rel=”tooltip” title=”Outboards are more easily accessible and serviceable. Inboards offer better refinement and potentially more power. Generally, smaller engines are petrol, with larger being diesel.”><img src=”img/info_icon.png” alt=”” width=”12″ height=”12″ border=”0″ align=”absmiddle” /></a> Engine </td><td width=”73%” class=”productspecsdetails”>’ . get_value_of(‘ENGINE’) . ‘</td></tr><tr><td valign=”middle” class=”productspecshdr”> <a rel=”tooltip” title=”Beds, in layman’s terms.”><img src=”img/info_icon.png” alt=”” width=”12″ height=”12″ align=”absmiddle” /></a> Berth</td><td class=”productspecsdetails”>’ . get_value_of(‘BERTH’) . ‘</td></tr><tr><td valign=”middle” class=”productspecshdr”> <a rel=”tooltip” title=”Essentially a bedroom – individual sleeping areas.”><img src=”img/info_icon.png” alt=”” width=”12″ height=”12″ align=”absmiddle” /></a> Cabins </td><td class=”productspecsdetails”>’ . get_value_of(‘CABINS’) . ‘</td></tr><tr><td valign=”middle” class=”productspecshdr”> <a rel=”tooltip” title=”Measured bow to stern (front to back).”><img src=”img/info_icon.png” alt=”” width=”12″ height=”12″ align=”absmiddle” /></a> Length </td><td class=”productspecsdetails”>’ . get_value_of(‘LENGTH’) . ‘</td></tr><tr><td valign=”middle” class=”productspecshdr”> <a rel=”tooltip” title=”The width from port to starboard (left to right).”><img src=”img/info_icon.png” alt=”” width=”12″ height=”12″ align=”absmiddle” /></a> Beam </td><td class=”productspecsdetails”>’ . get_value_of(‘BEAM’) . ‘</td></tr><tr><td colspan=”2″ align=”right” class=”productspecshdr”><a href=”../contact?ref=’ . get_value_of(‘TITLE’) . ‘”>Enquire</a> | <a href=”details.php?ref=’ . $boatfile . ‘”>View Details ></a></td></tr></table></td></tr></table></td></tr></table><br />’);
}
?>