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)?
Supress some serveroutput but not all
Hi,
Is this Safe or Unsafe?
Hi i made a few pages with lots of peoples help now i just want to know if they are safe or not can anyone help me?here are the codesRegisterCode: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
Syntax Help
I'm trying to make a form that edits a php file which contains config settings. I'm using strings that are defined by the user form inputs. This is what my file should look like when the form is
Small problem with image resize script
Hi!I am a little bit new to php and I have an issue installing an image resize script I downloaded (http://shiftingpixel.com/2008/03/03/smart-image-resizer/) and can't seem to get it working.Here's a
C++ Http request?
Code:
To add a field on the screen XK02.
Hi All,
Receive Rosettanet Message to SAP 4.6c
Dear all ,
Remove directories not empty
hi,i have an array that contains some names (1,4,6,56...). Every integer is a name of a folder.I must to delete only the folders in array, i use this code:Code: $all_folders = array();while ($row =
TabControl Inside ListView Not Editing
Hello everybodyI have a ListView on my page. Inside the ListView I put a TabControl, cuz I want to put different input controls on seperate pages. The problem is that changes made by the user in the
'210010106140040100' == '210010106140040101'
Debugging this simple line of a PHP scriptCode: if($a == $b){ } I've found that with value of$a = '210010106140040100' (type = string)$b = '210010106140040101' (type = string)the result of the