I have the below query:
SELECT l1.id as lev1_id,l2.id as lev2_id,l3.id as lev3_id,l1.category AS lev1, l2.category as lev2, l3.category as lev3
FROM categories AS l1
LEFT JOIN categories AS l2 ON l2.parentCat = l1.id
LEFT JOIN categories AS l3 ON l3.parentCat = l2.id
WHERE l1.parentCat = NULL
Which outputs something like:
-------------------------------------------------------
lev1_id | lev2_id | lev3_id |lev1 | lev2 | lev3 |
------------------------------------------------------
1 | 4 | 7 |makeup | lipstick | wet look
1 | 4 | 8 |makeup | lipstick |matt
1 | 5 | 9 |makeup | mascara| black
2 | 11 | NULL|skincare|creame | NULL
3 | 12 | 13 |haircare |hairspray| Xtra Hold
I loop through the results and list all the categories and subcategories as below.
$prevCat1Name = '';
$prevCat2Name = '';
foreach ($all_cats as $cats) {
if ($cats['lev1'] !== $prevCat1Name) {
echo $cats['lev1'];
}
if (($cats['lev2'] !== $prevCat2Name)&&($all_cat['lev2'] !== NULL)) {
echo ' - ' .$cats['lev2'];
}
if (($cats['lev3'] !== NULL)&&($all_cat['lev2'] !== NULL)) {
echo ' -- ' . $cats['lev3'] . PHP_EOL;
}
$prevCat1Name = $all_cat['lev1'];
$prevCat2Name = $all_cat['lev2'];
}
How do I amend the above code so that i can expand / contract the sublevels (without having seperate queries for each level)?
Local file browser with php
Halo..So this is what i want to create. I have a folder that i share and it has many movies..So i will setup a local web browser and i want to make a .php file that after you login it will saw you the
Hashing?
Hi, I was hoping to take a string value then convert it - consistently - across each of our pages into a alphanumeric value. I figured the hash function would be able to accomplish this; the results
Binding 2 UDP sockets on same port, connected to different destinations, 1 receives
Hello,
php sessions,logouts & the bloomin back button!
Hi All,I've got a cms that members can log into. When they logout, the session is destroyed, however, if you click the back button, you can get back into the CMS.How can I get around this?My logout
remove a ; from emails in textarea
Code: <?php session_start(); $database_host = "localhost"; $database_username = ""; $database_password = ""; $database_name =
what business processes?
Hi,
Logic question
im wondering what's the best method to do the above list:it is for alliance @ MMORPG game -the administrator of alliance have 10 slots for creating ranks ... each rank have it's own permissions (in
When file included, REMOTE_ADDR is server's?
I have an index file that handles my site, basically index.php?page=ip will activate "require('./ip.php')".In the included file I have $ip = $_SERVER['REMOTE_ADDR']; and when it FIRST
Session problem?!?
Hello All! I am very new to the php world but I am working on fixing things that a previous programmer screwed up for a site that I have. Let me explain what the current issue is. I believe it had to
Online Event Ticket Sales
Has anyone wrote a script for online tickets sales?I have been googling and found lots of third party solutions. I was hoping to adapt a digital goods sale script. Is it possible to have a ticket sent