I'm trying to figure out how to make this code work. Basically i have used MySQL to fetch an associative array containing multiple values.
example database: database name = Products
----------------------------------------------------------------.
| name | overcategory | category | subcategory |
| Talon | null | stud welding | capacitor discharge |
| cdss m3x40 | studs/bolts | cd-studs | stainless steel |
----------------------------------------------------------------.
I used the sentence SELECT name, overcategory, category, subcategory FROM Products WHERE 1 = 1;
In the actual database there are more entries, but they are not relevant for this question.
The result i want to output as a menu on the left hand side of the screen.
<nav>
<h1> "$overcategory" </h1>
<h2> "$category" </h2>
<h3> "$subcategory" </h3>
<a href = "">$productname </a>
<a href = "">$productname3 </a>
<h1> "$overcategory2" </h1>
<h2> "$category2" </h2>
<h3> "$subcategory2" </h3>
<a href = "">$productname2 </a>
</nav>
i was thinking of doing this by creating a multidimensional array that would look something like this:
$testArray = array(
''=>array(
'Boltsveiseapparater'=>array(
'Kondensator'=>array(
'Talon',
'LBS-75'
),
'Arc'=>array(
'LBH-410',
'LBH-800'
)
)
),
'Pinner/bolter'=>array(
'CD-pinner'=>array(
'rustfri'=>array(
'cdss m3x35',
'cdss m3x40'
),
'stål'=>array(
'cdms m3x35',
'cdms m6x35'
),
'Alu'=>array(
'cdal m3x10',
'cdal m8x80'
)
),
'Bossinger'=>array(
'Stål'=>array(
'M6x10 5x8',
'M5x12 4x10'
),
'Alu'=>array(
'M6x10 5x8',
'M5x12 4x10'
),
'Rustfri'=>array(
'M6x10 5x8',
'M5x12 4x10'
)
)
)
);
I have no idea how to do this by looping through the results. is there any way of doing this without making a giant array of doom? if not, can someone assist me in decyphering this conundrum.
Thank you in advance. BM.