Retrieving more records from 1 field
Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Database Discussion
Forum Description: Discussion and chat on database related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=6401
Printed Date: 29 March 2026 at 10:53am Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com
Topic: Retrieving more records from 1 field
Posted By: zaboss
Subject: Retrieving more records from 1 field
Date Posted: 14 October 2003 at 6:54am
|
I have a field (TestID) in which I store the ID of the quizes a user is allowed to take. It could be 1 records, could be several, coma delimited (like 1, 2, 39, 103).
How could I pull them from db one by one? as I need to pass them to a query string like in examiner.asp?quizID=1?
------------- Cristian Banu
http://www.soft4web.ro - Soft 4 web
|
Replies:
Posted By: michael
Date Posted: 14 October 2003 at 8:19am
I would query the whole field and split the values into an array. will be easier to work with that way.
------------- http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker
|
Posted By: zaboss
Date Posted: 14 October 2003 at 8:26am
|
Kind of knew that, but I do not know how to write it ! I have tryed
<% dim i, j i=1 Set rs= MyConn.Execute("Select TestID from Login Where UserName = '" & Session("UserName") &"'") While i < len(rs("TestID")) j=instr(i, ",", rs("TestID")) response.write("<p><a href = examiner.asp?quizID=" & mid(rs("TestID"), i, j-i-1) & ">" & "Test " & i & "</a></p>") i=j+1 Wend rs.close set rs = nothing%></p>
But it triggers the error : Invalid procedure call or argument: 'mid'
------------- Cristian Banu
http://www.soft4web.ro - Soft 4 web
|
Posted By: michael
Date Posted: 14 October 2003 at 12:24pm
|
dim i,counter, testids Set rs= MyConn.Execute("Select TestID from Login Where UserName = '" & Session("UserName") &"'") testids = Split(rs("TestID"),",") i = ubound(testids) For counter = 0 to i Response.Write "TestID= " & testid(counter) NEXT
|
This should work, have not tested it, just give it a shot...
------------- http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker
|
Posted By: zaboss
Date Posted: 14 October 2003 at 3:33pm
Thanks Michael, that worked. 
------------- Cristian Banu
http://www.soft4web.ro - Soft 4 web
|
Posted By: Flamewave
Date Posted: 15 October 2003 at 11:42am
Seems like an awful lot of overhead, if you are intrested in improving the performance of this, I would create another table that has a column for the user id and a colum for the test id, and then enter in a single record for each test id that the user has access to, you can then use a select statement to find out if the user has access to that test, and skip all of the array splitting and comparison stuff asp side.
------------- - Flamewave
They say the grass is greener on the other side, but if you really think about it, the grass is greener on both sides.
|
Posted By: zaboss
Date Posted: 15 October 2003 at 12:38pm
Creating another table would fill the db with thousands of useless records. I think the performance would be much more affected while looping through thousands records than spliting one record into several others.
------------- Cristian Banu
http://www.soft4web.ro - Soft 4 web
|
Posted By: Flamewave
Date Posted: 16 October 2003 at 1:28am
Depends on what database you are using. If you are using SQL, then you can use stored procs and views to do the select statements, and its about 10x faster (well, maybe thats an exaguration) then looping through it ASP side, excpecially (damn I need to learn how to spell one of these days) if you have thousdands of recordsets. If you are using Access, then there probally wouldn't be much if any of a difference in speed between the two, although you can still use the "querries" section of Access to create an equivialnt of a view in SQL server, that can greatly speed up the performance. If its something other then Access or SQL, I don't know enugh about them to voice my opinion on performance with them.
------------- - Flamewave
They say the grass is greener on the other side, but if you really think about it, the grass is greener on both sides.
|
Posted By: Bunce
Date Posted: 16 October 2003 at 4:28am
|
zaboss.... one word... normalise!!! 
You shouldn't have multi-value data in a single field. Heaps of reasons against doing this, and if anything, performance will ususally improve.
Databases are designed and optimised to create and work with joins, not to run custom code requiring you to split values to work with them.
Flamewave is spot on.
Cheers, Andrew
------------- There have been many, many posts made throughout the world...
This was one of them.
|
Posted By: zaboss
Date Posted: 16 October 2003 at 11:29am
Still not understand why 3 lines of code are less efective and much resource consuming than thousands of redundant records. I must admit that my first thought was indeed to create a new table, but I thought that would add up redundant informations (we are talking here of thousands of students with 3-5 testes at least for each of them, so about 100.000 duplicate records. How could that be less resource consuming and efective then 3 lines of code?
------------- Cristian Banu
http://www.soft4web.ro - Soft 4 web
|
Posted By: michael
Date Posted: 16 October 2003 at 11:52am
|
There would be no redundant data if you normalize the db like I think Falmewave said. If you just create a table e.g. StudentID TestID
In there you store all tests they are set up for. StudentID linking to the Student table and TestID to the test table. Would cause much less overhead because the database once gotten the request will work everything off and just return the results you need without having asp to use array data and work through it...
------------- http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker
|
Posted By: zaboss
Date Posted: 16 October 2003 at 12:16pm
|
I see were you guys pointing... But I think this is too much trouble because the app has a different target. This is for companies to test either their employees, either people applying for jobs. Therefore, most likely a user will enter the app only once. There are 90% chances that a user account would be used only 1 time, then deleted. So, storring all than in another table (although linked) would cause more trouble that it is supposed to sort.
Not to mention that this is using mySQL which anyway forbide me to use inner joins or stored proc. (But there are Access and SQL Server versions of the app - now I design all my apps with 3 diferent backends dbs).
------------- Cristian Banu
http://www.soft4web.ro - Soft 4 web
|
Posted By: Bunce
Date Posted: 16 October 2003 at 4:44pm
|
why is it redundant data? You're stll inserting the same data - its just that you're doing it properly!
The target of the app is prety much irrelevant. We're talking about general database design.
Here's a quick link, but there's heaps on normalisation if you googe it: http://www.troubleshooters.com/littstip/ltnorm.html - http://www.troubleshooters.com/littstip/ltnorm.html
Cheers, Andrew
------------- There have been many, many posts made throughout the world...
This was one of them.
|
|