zippers24 Posted July 13, 2008 Share Posted July 13, 2008 I am trying to create a dynamic drop down box of possible colours for a product, the query returns the colours in a string ie Green,Blue,Red... I know that normally you would use the explode function, well i imagine you still do. But I want the text box to appear in the following tpl file: {load_product assign="product"} <br/><br/> <span class="ListDescription">{$product->mProduct.name}</span><br><br> <table> <tr> <td width="250"> <img src='product_images/{$product->mProduct.image_file_1}' height="150" border="0"></a> </td> <td> <img src='product_images/{$product->mProduct.image_file_2}' height="150" border="0"></a> </td> </tr> </table> <br/> <span class="ProductDescription">{$product->mProduct.description}<br/><br/> Fabric: </span> <span class ="ProductFabric">{$product->mProduct.fabric}<br/><br/> Weight: </span> <span class ="ProductWeight">{$product->mProduct.weight}<br/><br/> Price: </span> <span class="ProductPrice">£{$product->mProduct.price}<br/><br/> Sizes: </span> <span class="ProductSize">{$product->mProduct.sizes}<br/><br/> Colours: </span> <span class="ProductColour">{$product->mProduct.colours}<br/><br/> </span> <a class="Link" href="{$product->mPageLink}">Continue Shopping</a> But their is also a seperate function which retrives the product details, i imagine this is where you would create the array of colours: <?php // plugin function for the load_product function plugin function smarty_function_load_product($params, $smarty) { $product = new Product(); $product->init(); // assign template variable $smarty->assign($params['assign'], $product); } // class that handles product details class Product { // public variables to be used in Smarty template public $mProduct; public $mPageLink = "index.php"; // private stuff private $mBoCatalog; private $mProductId; // class constructor function __construct() { // create the middle tier object $this->mBoCatalog = new BoCatalog(); // variable initialization if (isset($_GET['ProductID'])) $this->mProductId = (int)$_GET['ProductID']; else trigger_error("ProductID required in product.php"); } // init function init() { // get product details from business tier $this->mProduct = $this->mBoCatalog->GetProductDetails($this->mProductId); if (isset($_SESSION['PageLink'])) $this->mPageLink = $_SESSION['PageLink']; } } //end class ?> I have had a few attempts at this and not had much sucess so any ideas anyone has on this issue would be much appreicated. Andy Link to comment https://forums.phpfreaks.com/topic/114517-creating-a-dynamic-text-box-from-a-string-in-myql/ Share on other sites More sharing options...
wildteen88 Posted July 13, 2008 Share Posted July 13, 2008 Heres is some example code for turning a comma delimited list in to a pull down menu $color_str = 'red,blue,green'; $colors = explode(',', $color_str); echo '<select name="color">'; foreach($colors as $color) { echo "\n <option value=\"$color\">" . ucwords($color) . '</option>'; } echo "\n</select>"; Link to comment https://forums.phpfreaks.com/topic/114517-creating-a-dynamic-text-box-from-a-string-in-myql/#findComment-588874 Share on other sites More sharing options...
zippers24 Posted July 13, 2008 Author Share Posted July 13, 2008 Thanks, but how could i make a dynamic string from $product->mProduct.colours? Link to comment https://forums.phpfreaks.com/topic/114517-creating-a-dynamic-text-box-from-a-string-in-myql/#findComment-588876 Share on other sites More sharing options...
wildteen88 Posted July 13, 2008 Share Posted July 13, 2008 How is that variable created, Sorry I have not used smarty so I don't know the language. Edit. Those smarty variables must be set from this line: $smarty->assign($params['assign'], $product); $params['assign'] must hold an array of variables to be set in smarty. Link to comment https://forums.phpfreaks.com/topic/114517-creating-a-dynamic-text-box-from-a-string-in-myql/#findComment-588880 Share on other sites More sharing options...
zippers24 Posted July 13, 2008 Author Share Posted July 13, 2008 So would i have to create the array from the string in the template? Something like: {load_product assign="product"} <br/><br/> [b]<?php $product_colours={$product->mProduct.colours}; $colours_array = explode(',', $product_colours); ?>[/b] <span class="ListDescription">{$product->mProduct.name}</span><br><br> <table> <tr> <td width="250"> <img src='product_images/{$product->mProduct.image_file_1}' height="150" border="0"></a> </td> <td> <img src='product_images/{$product->mProduct.image_file_2}' height="150" border="0"></a> </td> </tr> </table> <br/> <span class="ProductDescription">{$product->mProduct.description}<br/><br/> Fabric: </span> <span class ="ProductFabric">{$product->mProduct.fabric}<br/><br/> Weight: </span> <span class ="ProductWeight">{$product->mProduct.weight}<br/><br/> Price: </span> <span class="ProductPrice">£{$product->mProduct.price}<br/><br/> Sizes: </span> <span class="ProductSize">{$product->mProduct.sizes}<br/><br/> Colours: </span> <span class="ProductColour">{$product->mProduct.colours}<br/><br/> </span> <a class="Link" href="{$product->mPageLink}">Continue Shopping</a> Link to comment https://forums.phpfreaks.com/topic/114517-creating-a-dynamic-text-box-from-a-string-in-myql/#findComment-588899 Share on other sites More sharing options...
zippers24 Posted July 13, 2008 Author Share Posted July 13, 2008 After messing about a bit I reckon the explode statement needs to go in the function; function.load_product.php At present I am just trying to create a variable that contains only the colours so i can explode it inot an array. I have tried the following but I get "Undefined variable: product." <?php // plugin function for the load_product function plugin function smarty_function_load_product($params, $smarty) { $product = new Product(); $product->init(); $product->getColours(); // assign template variable $smarty->assign($params['assign'], $product); } // class that handles product details class Product { // public variables to be used in Smarty template public $mProduct; public $mcolours; public $string1 = "hello"; public $mPageLink = "index.php"; // private stuff private $mBoCatalog; private $mProductId; // class constructor function __construct() { // create the middle tier object $this->mBoCatalog = new BoCatalog(); // variable initialization if (isset($_GET['ProductID'])) $this->mProductId = (int)$_GET['ProductID']; else trigger_error("ProductID required in product.php"); } // init function init() { // get product details from business tier $this->mProduct = $this->mBoCatalog->GetProductDetails($this->mProductId); if (isset($_SESSION['PageLink'])) $this->mPageLink = $_SESSION['PageLink']; } function getColours() { //get colours $this->mcolours= $this->$product->mProduct.colours; } } //end class ?> If anyone has anyone has any ideas I would be most grateful. Link to comment https://forums.phpfreaks.com/topic/114517-creating-a-dynamic-text-box-from-a-string-in-myql/#findComment-588946 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.