I have been stuck trying to get the logic of a silly piece of code working since yesterday evening.
What I'm doing is generating some simple JavaScript for a "select" menu later. There are categories, and subcategories in a CMS thing I'm working on. I am making a JavaScript form that will show categories in one select box, and then when a user selects a different category, a second select box shows the subcategories that are in the category.
Here's what the code looks like so far:
$last_c_id = 0;
$first_flag = 0;
while($db->next_record()):
if (($db->Record["c_id"] != $last_c_id) && ($first_flag == 0)) {
echo "<b>output {</b><br>";
echo "do some REGULAR stuff...<br>";
$first_flag = 1;
} else if (($db->Record["c_id"] != $last_c_id)) {
echo "closing brace }<br>";
} else {
echo "do some stuff...<br>";
}
$first_flag = 0;
endwhile;
and the reason why the database connection code looks funky, I'm using a class for it. Basically my logic goes like this:
pseudocode
flag = 0
WHILE there is another record
if record id is not equal to the last record id checked
AND if flag is 0
output ... {
output option
flag = 1 // flag 1 means that we have done the open {
end if
else if record id is not equal to the last record id checked
AND if flag is not 0
output }
flag = 0 // flag 0 means that we are done with the block }
end if
else
output option
last record = record id
END WHILE
But I end up with this type of output:
output {
do some REGULAR stuff...
do some stuff...
output {
do some REGULAR stuff...
output {
do some REGULAR stuff...
output {
do some REGULAR stuff...
output {
do some REGULAR stuff...
It doesn't get to the closing } part. This must be a really easy thing to fix, or even do a bit differently. But i've been trying many different approaches, but keep getting stuck. I guess I basically need to make the code add an ending } when there are no more subcategories in a category.
This is a dumb question, but I am pressed for time, haha lame. Anyway, any help would be appreciated.