Jump to content

PHP Newbie


ChrisCwmbran

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.