Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 1st, 2006, 03:06 PM
Friend of Wrox
 
Join Date: May 2005
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default comma split prolem

I asked this question before.I got the following query but it does not work
I have a field in my database called "interests"
the values that will be stored in this field will be numbers like this 1,2,3
and each number respresents an interest for ex. 1=sport 2=music
I have the following function but it does not work!
first it inserts the record in the db.I want to update a specific field
second when I even user the insert with loop it inserts multiple record with each field with one splitted value
My request:I store the value of interest field for each user in the db like this(1,2,3)
How can I display the record with the original name
for ex.records in db 1,2,3
display records like this sport,music,computer





dim ids,numOfIds,count
     count = 0

     Function splitOnComer(stringVar)
        if isNull(stringVar) then
           'do nothing
        else
           ids = Split(stringVar, ",", -1, 0)
           numOfIds = (UBound(ids) +1)
        end if
     End function

     splitOnComer(request.form("gId"))
     do until count = numOfIds
        sql = "INSERT INTO userGroups(gid)VALUES(" & trim(ids(count)) & ");"
        conn.execute(sql)
        count = (count + 1)
     loop


 
Old May 1st, 2006, 05:44 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There are many options for this... so you can be creative.

First off... you probably know this, but you are breaking the one of the rules of the first normal form of relational database... you are storing multiple values in a single field of a record. If you wernen't doing that this would simply be a matter of a sql query.

Anyway - here are a few ideas,
You could have a function to which you pass each interest id, and which returns the string associated with it:

function getInterest(byval interestId)
    Select Case clng(interestId)
        Case 1
            getInterest = "sport"
        Case 2
            getInterest = "music"
        Case 3
            getInterest = "programming"
        Case 4
            getInterest = "drinking"
    end select
end function

Alternatively, you could create an array that holds all the values for each id:

    arrInterests = split("sport:music:programming:drinking", ":")


and then access them in a similar method:

function getInterest(byval interestId)
    getInterest = arrInterests(clng(interestId))
end function

These are just a few ideas...
You could use a dictionary object as well, or make an clsInterests class to provide the services... etc.



Woody Z http://www.learntoprogramnow.com
 
Old May 1st, 2006, 06:20 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Interesting, you say:
;;;I asked this question before.I got the following query but it does not work

I was the person who posted it, where does this code fail? Have a look at this post:

http://p2p.wrox.com/topic.asp?TOPIC_ID=43070
This person said "Hi mat41 the code worked like a dream"

You are asking a different question all together:
;;;How can I display the record with the original name
That function was never going to give you this

FYI as woodyz said check out normalization regarding good database design. Good practice says you should be storing an integer that represents a string

Wind is your friend
Matt
 
Old May 2nd, 2006, 01:29 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

matt this was not me who said "it worked like a dream"

 
Old May 2nd, 2006, 01:55 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Yes I realize this, as I said:
"This person said "Hi mat41 the code worked like a dream""

The operative words being 'this person'

All I was doing was replying to your comment:
;;;I got the following query but it does not work
It does work. You are obviously trying to do something other than what its supposed to do. Can I assist you making it do what you want it to do?



Wind is your friend
Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
Signout Prolem [email protected] ASP.NET 1.0 and 1.1 Basics 4 April 5th, 2006 01:59 AM
How do I get rid of this comma?!?!?!?! tsindos Classic ASP Databases 10 February 16th, 2006 12:55 AM
How to get rid of this comma!!?! gilgalbiblewheel Classic ASP Databases 15 August 8th, 2005 06:41 PM
comma problem! Ashleek007 Beginning PHP 2 April 17th, 2005 04:14 PM
prolem in connection pools Upendra Verma J2EE 2 September 10th, 2004 12:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.