Note that there are some explanatory texts on larger screens.

plurals
  1. POcreate instance of two classes together
    primarykey
    data
    text
    <p>Im trying to display two list: one for categories and brand but only the categories are being displayed. And when I remove the code for categories, the brands are being displayed. Is it because it is not possible to create instances of two classes in the same php page? In index.php:</p> <pre><code> &lt;?php $obj = new CategoryList(); if (method_exists($obj, 'init')) { $obj-&gt;init(); } for($i = 0;$i&lt; count($obj-&gt;mCategory); $i++) { echo "&lt;a href=''&gt;"; echo $obj-&gt;mCategory[$i]['name']. "&lt;br/&gt;"; echo "&lt;/a&gt;"; } $obj2 = new BrandList(); if (method_exists($obj2, 'init')) { $obj2-&gt;init(); } for($i = 0;$i&lt; count($obj2-&gt;mBrand);$i++) { echo "&lt;a href=''&gt;"; echo $obj2-&gt;mBrand[$i]['name']. "&lt;br/&gt;"; echo "&lt;/a&gt;"; } ?&gt; </code></pre> <p>Here's the code for the classes:</p> $mSelectedCategory = (int)$_GET['category_id']; } public function init() { $this->mCategory = Catalog::GetCategory(); } } ?> <pre><code>&lt;?php class BrandList { public $mSelectedBrand = 0; public $mBrand; public function __construct() { if (isset ($_GET['brand_id'])) $this-&gt;$mSelectedBrand = (int)$_GET['brand_id']; } public function init() { $this-&gt;mBrand = Catalog::GetBrand(); } } ?&gt; </code></pre> <p>Maybe this might help:</p> <pre><code>class Catalog { //get id and name of category public static function GetCategory() { $sql = 'CALL catalog_get_category_list()'; return DatabaseHandler::GetAll($sql); } public static function GetBrand() { $sql = 'CALL catalog_get_brands_list()'; return DatabaseHandler::GetAll($sql); } } </code></pre> <p>in DatabaseHandler class:</p> <pre><code> public static function GetAll($sqlQuery, $params = null, $fetchStyle = PDO::FETCH_ASSOC) { $result = null; try { $database_handler = self::GetHandler(); $statement_handler = $database_handler-&gt;prepare($sqlQuery); $statement_handler-&gt;execute($params); $result = $statement_handler-&gt;fetchAll($fetchStyle); } catch(PDOException $e) { self::Close(); trigger_error($e-&gt;getMessage(), E_USER_ERROR); } return $result; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload