ChrisCwmbran Posted April 19, 2013 Share Posted April 19, 2013 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. Link to comment https://forums.phpfreaks.com/topic/277146-php-newbie/ Share on other sites More sharing options...
lemmin Posted April 19, 2013 Share Posted April 19, 2013 Is productID in the URL? When you say "nothing," do you mean a completely blank white page? Have you checked your error logs? Link to comment https://forums.phpfreaks.com/topic/277146-php-newbie/#findComment-1425794 Share on other sites More sharing options...
Barand Posted April 19, 2013 Share Posted April 19, 2013 It looks as though passing a productID and no mID will not give any output Link to comment https://forums.phpfreaks.com/topic/277146-php-newbie/#findComment-1425795 Share on other sites More sharing options...
ChrisCwmbran Posted April 19, 2013 Author Share Posted April 19, 2013 I didn't know I had any error logs - at least I have no idea where to find them. The heading produced is just: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv="Content-Type" content="text/html; charset=windows-1252"></HEAD> <BODY></BODY></HTML> Is if ($_GET['mID']) { . . . } elseif ($_GET['productID']){ . . . } else { . . . } Ok? Im not sure if the if statement can test for a variable passed in the URL like this? Link to comment https://forums.phpfreaks.com/topic/277146-php-newbie/#findComment-1425798 Share on other sites More sharing options...
ChrisCwmbran Posted April 19, 2013 Author Share Posted April 19, 2013 It looks as though passing a productID and no mID will not give any output The idea is the page with the code included can be called with an mID in the url, or a productID, and in the event that neither are supplied it does a third thing. Link to comment https://forums.phpfreaks.com/topic/277146-php-newbie/#findComment-1425799 Share on other sites More sharing options...
ChrisCwmbran Posted April 19, 2013 Author Share Posted April 19, 2013 Let me try to explain better: The code is included in a joomla page, and initially has no variables passed in the URL, and in which case it is supposed to use the "} else {" clause. Depending on the user selecting a link the page is then called again passing an mID in the URL and is supposed to use the "if ($_GET['mID']) {" clause. Again a selection is made and the page is called back again, this time passing a productID in the URL and is supposed to use the "} elseif ($_GET['productID']){" clause. Link to comment https://forums.phpfreaks.com/topic/277146-php-newbie/#findComment-1425802 Share on other sites More sharing options...
Jessica Posted April 19, 2013 Share Posted April 19, 2013 You need to turn on error_reporting set to E_ALL and find out what errors are being produced. Link to comment https://forums.phpfreaks.com/topic/277146-php-newbie/#findComment-1425809 Share on other sites More sharing options...
ChrisCwmbran Posted April 19, 2013 Author Share Posted April 19, 2013 Parse error: syntax error, unexpected '}' in D:\Websites\Joomla Sites\dev.micromuseum.co.uk\php\manufacturer.php on line 62 I still can't see why though. Link to comment https://forums.phpfreaks.com/topic/277146-php-newbie/#findComment-1425818 Share on other sites More sharing options...
ChrisCwmbran Posted April 19, 2013 Author Share Posted April 19, 2013 Actually I have now found it! Thanks all for your help! I do also get some errors reading: Notice: Undefined index: productId in D:\Websites\Joomla Sites\dev.micromuseum.co.uk\php\manufacturer.php on line 6 For example, but the page does work. Im not quite sure I follow what this is trying to tell me. Link to comment https://forums.phpfreaks.com/topic/277146-php-newbie/#findComment-1425825 Share on other sites More sharing options...
seandisanti Posted April 19, 2013 Share Posted April 19, 2013 it's telling you that on line 6, you're trying to access $_GET['productId'] without verifying that it's set. make use of isset() to avoid that one Link to comment https://forums.phpfreaks.com/topic/277146-php-newbie/#findComment-1425838 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.