Seeking Help on the Internet
29 06 2007I know, I know. I always start these posts with some sort of long explanatory section before I get to the gist of what the post is about. I have this thing where I feel the need to tell the background whether or not others want to know about it. You’ve been warned.
Two weeks ago I was messing around with putting checkboxes in a web form. I had written my own routine for this in 1999, but because I use dreamweaver widgets for almost everything now, I decided to try a checkbox tool and it proved problematic.
What happens with the form is that the users select any number of checkboxes. The value of each checkbox is a number, but the user sees text (In this case the names of our Intranet web apps). All I do when the user submits the form is save the user id and the number values. Later, when I need to show the user what they have selected, I take the number of the check box and match it to another database table that has the same number plus the URL and name of the web app. So, in total I’m working with three database tables:
STAFF
staffid username position department .
75 johnr webmaster development
62 joshl Net Engineer network
WEBAPPS
appid title URL
1 Training Management System train.php
2 Staff Calendar cal.php
3 Human Resources hr.php
APPS_LOOKUP
appid userid
1 75
2 62
2 75
3 75
3 62
APPS_LOOKUP is what’s called a lookup table and this lookup table holds the results of the checkboxes that each user clicked. Without a lookup table I would probably store all of the web apps links for each user in the STAFF table, and with many web apps on our intranet this table would soon become ungainly and slow to search. Our current Intranet page contains over 30 links haphazardly listed on the home page. The idea for the new intranet was for staff members to choose only the links they usually use, and see those when they log in.
So, that’s easy enough to do, but the checkbox widget I used stored the data as comma separated values:
APPS_LOOKUP
appid userid
1,2,3 75
2,3 62
I had never worked or seen data stored like this before within a SQL field, and in fact, it went against what I had learned about storing data in lookup tables. I needed to know if there was some sort of SQL statement I could put together to accomplish pulling each value out of the appid field so I could relate it to the data stored in the WEBAPPS table. Interestingly enough, there was no Dreamweaver widget to store checkbox data into a traditional lookup table format, and the documentation for the widget I was using expected you to output the data like this:
johnr| Training Management System, Staff Calendar, Human Resources
I needed to output each webapp separately, so I was going to need help. Instead of doing a Google search I decided to try the comp.databases.mysql newsgroup. For my problem it was best that I explain exactly what I wanted to do. The responses to my query?
The first response basically told me that it was wrong to store data as comma separated in a field, rather that the data should be separate. I was then hit with some sort of quote about SQL empirical data. My reply was that the data was entered this way in the table, and again asked if there was a SQL routine I could use to separate it.
This first response really ticked me off. One of the things I see many times in forums is someone asking for specific help using IIS and Windows Server. One can almost guarantee that one of the responses will be “you should be using Apache and Linux.” Please, just answer the question or don’t say anything. In my case I was quite aware that my data was not stored “empirically”, but that wasn’t my question.
The second response was a link where a coder did a fairly complicated routine using MySQL 5 with stored procedures.. Not a help since my app is for MySQL 3, and stored procedures are not a part of that version, besides not knowing a thing about stored procedures.
The third response basically reiterated what the first reply said, plus chastising me for “top posting” in reply. I’m going to write a short post (I promise)about top posting next week, and ask Alvin for a TSPY ruling.
My next step was a Google search, and I found several topics with people seeking the same answer as I was. One particular thread had a response from a coder where he made a very convincing argument for how comma separated values in a field could save lots of searching time. Outside of the stored procedure solution, I found no SQL solution to my problem. I ended up doing what I should have done in the first place, and solved my problem in about an hour using a PHP array, but I was sure there had to be some sort of easy SQL solution out there somewhere. I know there are other people out there with this problem, so I’ll try to post my code in a comment to this post.
Print This Post
Comments : 1 Comment »
Categories : Educational Technology, Work Related
Send to Twitter


















Recent Comments