Jump to content

ChrisCwmbran

Members
  • Posts

    10
  • Joined

  • Last visited

Everything posted by ChrisCwmbran

  1. Thanks. Before I read your post I was thinking along the lines of: SELECT * FROM manufacturer m WHERE m.manufacturer IN (SELECT p.manufacturer FROM product p WHERE p.productType=2); But I don't think that's a join - and its close to midnight here so my brain is starting to melt. I'll read up on joins. I did lots of SQL training with Oracle but that was 22 years ago and I haven't used it at all since! Thanks for your response!
  2. Hey all, Here is a brief(ish) explanation of my problem. I've omitted all fields that aren't relevant to the query. I have three tables. 1. manufacturer which contains an fields called manufacturerID (type int) and manufacturerName (type varchar). 2. productType which contains fields called productTypeID (type int) and productDescription (type varchar) 3. product which contains fields productID (type int), productName (type varchar), manufacturer (type int) and productType (type int) Now for example, a kind of product type is "Monitor" and that has a productTypeID of 2. I want to list all manufactrurerName where one or more products made by that manufacturer are monitors i.e. all manufacturers who made monitors. I can do this using more than one query but I suspect there is a way of doing this in a single query. Can anyone tell me how this is done please? Thanks in advance! I've been trying to get my head around this for several hours! Chris.
  3. The manufacturer table only contains one record with a matching manufacturerID so should return a single record. Similarly the product table should only return a single record with a matching productID. Im only just learning so I have no idea how to do a joined query.
  4. Hi all I have a fragment of code here that doesn't work and produces a "Notice: Trying to get property of non-object" warning. // // productID was passed so display product record // // Load product record relating to productID // $sql = "SELECT * FROM product WHERE productID = " . $_GET["productID"]; $db->setQuery($sql); $product = $db->loadObjectList(); // // Load relevant Manufacterer record // $sql2 = "SELECT * FROM manufacturer WHERE manufacturerID = {$product->manufacturer}"; $db2->setQuery($sql2); $manufacturer = $db2->loadObjectList(); It appears that in the second query that the reference to $product->manufacturer doesn't work, but I don't really understand why. Thanks in advance for reading this, and any responses. Chris.
  5. 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.
  6. 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.
  7. 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.
  8. 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.
  9. 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?
  10. 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.
×
×
  • 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.