Note that there are some explanatory texts on larger screens.

plurals
  1. POLayer navigation menu
    primarykey
    data
    text
    <p>i have 3 tables, top_category, bottom_category, products, at the moment i have listed the top_category, i am confused about how to approach listing the second category but have it list so it knows what top_category it belongs too, this is why i have the foreign keys parent, so if the top_category for example is:</p> <pre><code>prod1 prod2 prod3 etc </code></pre> <p>and now i want to load my bottom category into these top_categories like this:</p> <pre><code>prod1 -subprod1 -subprod2 -subprod3 prod2 -subprod4 -subprod5 prod3 -subprod6 etc </code></pre> <p>This is my database:</p> <pre><code>CREATE TABLE top_category ( id INT PRIMARY KEY, NAME VARCHAR(100) ); CREATE TABLE bottom_category ( id INT PRIMARY KEY, NAME VARCHAR(100) , top_category_id INT REFERENCES top_category ); create table product ( id int primary key, name varchar(100) , bottom_category_id int references bottom_category ); </code></pre> <p>This is my php &amp; html code:</p> <pre><code>&lt;?php include('dbconnect.php'); try { $result = $pdo-&gt;query(" SELECT * FROM top_category ORDER BY top_name ASC; "); } // end try catch (PDOException $e) { echo 'There was a error fetching the products.' . $e-&gt;getMessage(); exit(); } // end catch $products = array(); foreach ($result as $row) { $products[] = array('id' =&gt; $row['id'], 'top_name' =&gt; $row['top_name']); } ?&gt; &lt;div class="sidebar"&gt; &lt;h4 class="sidebar-header"&gt;Select Products&lt;/h4&gt; &lt;form class="nav-search-form"&gt; &lt;input type="search" name="search" placeholder="Search products"&gt; &lt;/form&gt; &lt;nav class="sidebar-links"&gt; &lt;ul&gt; &lt;li&gt;&lt;a id="red" href="index.php"&gt;New Products&lt;/a&gt;&lt;/li&gt; &lt;?php foreach ($products as $product): ?&gt; &lt;li&gt;&lt;a href="#"&gt;&lt;?php echo htmlspecialchars($product['top_name']);?&gt;&lt;/a&gt; &lt;?php endforeach; ?&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/nav&gt; &lt;/div&gt;&lt;!-- sidebar --&gt; &lt;div class="main-content"&gt; </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.
    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