On my project there're various search results of different content-types. For unimportant reasons, not all content-types carry a unique ID. However, I tried to write this loop that will detect IDless content-types, and will give them a unique ID.
Basically, the results look like this:
- Category ID 3
- Category ID 3
- Category ID 4
- NON-ID Category 1
- NON-ID Category 2
[...]
I tried this:
$current = $result->section;
// if there's a category ID -- use it
if ($current != null) echo $result->sectionid;
else
// if this is the first IDless category -- initialize. this happens once.
if ($virginity == true) {
$store = $current;
$virginity = false;
}
// if initialized and current category string is the same as stored category string -- print it
if (($virginity == 0) && ($store = $current)) {
echo $defaultID;
}
// if initialized and current category string is different from the stored category string -- set new default category +1 and print it
if (($virginity == false) && ($store != $current)) {
$defaultID = $defaultID++;
echo $defaultID;
$store = $current;
}
Can you see where I'm going here? Trying to give each new category that comes up in the search results a unique ID, on the next loop session - check if the category string is same as the previous one, if so -- use the same ID, else -- bump ID by 1, print the new ID and store a new category.
However: This doesn't work properly.
Why?