Hi all,
Sorry to make a first post which is a plea for help, but whilst I've programmed quite a lot historically I'm very new to PHP and the only person I know who can write php is on holiday.
I have a bit of PHP code I've done which is included in a page of a Joomla website.
I suspect the problem is with my main if....elseif....else statement, but the page is returning nothing.
<?php
//
// Database setup
//
$db = & JFactory::getDBO();
$productTypeID = $_GET['productId'];
if (strlen($productTypeID == 0)) {
$productTypeID = 1;
}
if ($_GET['mID']) {
//
// mID was passed so display company details
//
$query = "SELECT * from manufacturer where manufacturerID = " . $_GET["mID"];
$db->setQuery($query, 0, $count);
$row = $db->loadObject();
$heading = $row->manufacturerName;
echo "<div class='itemHeader'>";
echo "<h2 class='itemTitle'><?= $heading ?></h2>";
echo "</div>";
echo "<br /><h4>Company History</h4>";
if ($row->manufacturerHistory){
echo "<p>{$row->manufacturerHistory}</p>";
} else {
echo "<p>Historic information about this company is currently unavailable. If you have any information to contribute to this section then please let us know!</p>";
}
//
// Display product list for company passed in mID
//
$query = "SELECT * from productType order by productTypeID";
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row2) {
$sql = "SELECT * from product where productType= {$row2->productTypeID} and manufacturer = {$row->manufacturerID}";
$db->setQuery($sql);
$rs = $db->loadObjectList();
if (count($rs)>0){
echo "<h4>{$row2->productDescription}</h4>\n";
foreach($rs as $item){
$sql = "SELECT assetID FROM asset WHERE product ={$item->productID}";
$db->setQuery($sql);
$prods = $db->loadObjectList();
echo "<a href=\"?productID={$item->productID}\">".$item->modelName1."</a>";
$assetArr = array();
$assetCount=1;
foreach($prods as $prod){
$assetArr[] =" <a href=\"?assetID={$prod->assetID}\">[$assetCount]</a>";
$assetCount++;
}
echo implode($assetArr," | ");
echo "<br>";
}
}
}
} elseif ($_GET['productID']){
//
// productID was passed so display product record
//
}
} else {
//
// No mID was passed so display list of manufacturers
//
echo "<div class='itemHeader'>";
echo "<h2 class="itemTitle">Manufacturers</h2>";
echo "</div>";
$query = "SELECT distinct(m.manufacturerName), m.manufacturerID from manufacturer m, product p
where m.manufacturerID = p.manufacturer and p.productType = {$productTypeID}
order by m.manufacturerName asc ";
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row) {
echo "<a href=\"{$_SERVER['PHP_SELF']}?mID={$row->manufacturerID}\">{$row->manufacturerName}</a><br />";
}
}
Can anyone help please?
I suspect its something very stupid!
Thanks
Chris.