telophase: (Default)
telophase ([personal profile] telophase) wrote2009-01-13 02:42 pm
Entry tags:

Coding HEEEEEEEELP!!

ETA: You can ignore this now. I'm wiping the slate clean and restarting.




If you're not familiar with coding, PASS ON BY. This will only confuse you.


Right. So I have SQL query results that I'm attempting to write to the screen with checkboxes such that child categories are underneath their parent categories, and so that they display as three across, then start a new table row. I'm now thoroughly confused and mixed up and at the point where I'm not sure why it works as well as it does, much less as to why the parts that are screwing up are screwing up.



i is the counter I'm using to make the table cells. i=3, close this row, start another one.



[edit] The b0rked table code that it produces is here: http://www.magatsu.net/pic2/SQL-table-code.txt

You can see the problem - that final series of table cells ranging from Communication through Sociology all belong under Social Sciences. The script thinks they're child categories, and thinks that their parent category is Social Sciences, it's just that my counter is SOMEHOW getting off for them. It has to do with the placement of the counter in the script, and hence my logic, not the records themselves, as the categories that are affected change as I move the counter around.

I probably need to start over from scratch in building this table, and there's probably a far easier way to do it, but I'm too solidly in CONFUSION HELL right now to be capable of that at the moment.

The query results:



The code in question (please don't laugh): http://www.magatsu.net/pic2/SQL-code.txt

[identity profile] helen-keeble.livejournal.com 2009-01-13 09:19 pm (UTC)(link)
Warning: Although I'm a software engineer, it's been seven years since I last did anything with InSQL, and even that was just database queries.

Having spent five minutes working through the loop, it looks to me like the last column of cells can only ever contain 1 child item. The first time you go through the loop for this column (when i=2), it hits the 'i= i+1' line (as the parent item is different to the last parent). So i is now 3, and it writes the parent item and the first child into the cell. BUT then it goes back round the for loop again - and this time i==3, so it immediately makes a new line and sets i to 0.

I think what you want is for the test on i to be "make a new line if i=4" -- that is, one greater than the (one-based) index of the last column.

Basically, I think you've got a fencepost error! (off by one in your index count)

[identity profile] helen-keeble.livejournal.com 2009-01-13 09:20 pm (UTC)(link)
That is, try:

if i = 4 then
response.write "" & VbCrLf & "

[identity profile] telophase.livejournal.com 2009-01-13 09:24 pm (UTC)(link)
Yeah, that's what I figured. :D

[identity profile] telophase.livejournal.com 2009-01-13 09:23 pm (UTC)(link)
Just tried increasing the test to 4, and it breaks the table in a similar way - it puts 4 across, and breaks the final column after the first child item. So yeah, that narrows the problem down. XD

Thank you! I now have a new place to look (or something to avoid if I start from the beginning again).

[identity profile] helen-keeble.livejournal.com 2009-01-13 09:28 pm (UTC)(link)
Hmm, odd. That suggests that on the last column it's somehow consistently deciding that, no matter what, it must increase i.

I'd take a close look at the code in this if statement:
if parentID = parentIDFormer then
...

Can you get it to print some more debug info in the cell every time it prints a child item - the parent id and the parentidformer?

[identity profile] telophase.livejournal.com 2009-01-13 09:31 pm (UTC)(link)
I think, actually, I narrowed it down at least partially to this part:

	if i = 4 then
		response.write "" & VbCrLf & "

[identity profile] helen-keeble.livejournal.com 2009-01-13 09:53 pm (UTC)(link)
Damnit, LJ certainly screwed up _that_ comment. How do I make it leave code blocks alone??

In any case, the general gist was that examining the table source for 'Social Sciences' and comparing it to the previous category, we can see that extra tags are getting inserted because the code hits i=3, plonks down the end row code, sets i=0, carries on with the next item, and then hits i=0 again and plonks down [tr][td valign='top'] (angle brackets replaced to make LJ ignore them). The combination of which seems to cause weird formatting in the table.

I'm running up against the limits of my SQL table formatting knowledge now... :-)

[identity profile] telophase.livejournal.com 2009-01-13 09:56 pm (UTC)(link)
It leaves some code blocks alone, and not others. :)

I'm cleaning the slate and re-starting from my simple vertical list of parent/child checkboxes, to see if I can't redo it better and simpler. I think my biggest problem was in knowing when to close a table cell and when not to.

And to answer a question in your previous comment that's not in this one: no, I didn't really want that first blank column in there, but for some reason it seemed to make sense at the time. I can't explain it now. :D

[identity profile] helen-keeble.livejournal.com 2009-01-13 09:58 pm (UTC)(link)
Got to put this aside and go and do my own work now, unfortunately, but I still harbour deep suspicions about that i=3 i=0 ifelse statement. It just looks like it's in the wrong place to me. Maybe try moving it so that it's just after the i=i+1 statement?