I want to select 5 random records from my database..I tried to suft the net and foundout this sql
SELECT TOP (3) Question, Choice1, Choice2, Choice3, Choice4
FROM Question
But when i tried to execute,i t always gave me the most top 2 records. why?Is this sql statement woring?How can i select 5 random records from the database?
I have 30 numbers. I need to select randomly 10 out of the given 30. A number must not repeat ( eg. i can't have number 10 twice ). How can i do this??
Ok here is what I'm trying to do. I want to grab a random record from a specific table. This is how I am doing it now:
x = 0 Set rs = Conn.Execute("SELECT Count(*) as total FROM [user] WHERE active = '1'") If rs.EOF <> True then total = rs("total") End if Randomize timer randnum1 = int(rnd * total) If randnum1 = 0 then randnum1 = 1 End if rs.close set rs = nothing
Set rs = Conn.Execute("SELECT * FROM [user] WHERE id = '" & randnum1 & "' ") Now that would work fine, BUT the id is a autonumber int of 1.
Now look at this example. Let's say I have 50 records, so I have the ID values of 1 through 50. Now I delete record number 46. So now my count goes up to 49. So the random number will pull up ANY number between 1 and 49, so if it pulls up 46 then BAAAM record can not be found.
There has to be an easier/more efficient way of getting a random record. I don't plan on deleting any records, but I just don't feel this is the best way of doing this.
<% Dim oConn, oRS, randNum Randomize() randNum = (CInt(1000 * Rnd) + 1) * -1 Set oConn=Server.CreateObject("ADODB.Connection") Set oRS=Server.CreateObject("ADODB.recordset") oConn.Provider="Microsoft.Jet.OLEDB.4.0" oConn.Open Server.MapPath("temp.mdb")
oRS.Open "SELECT TOP 1 EMAIL_ADDRESS, r = Rnd(" & randNum & ") FROM TABLE1 ORDER BY r", oConn, adOpenStatic, adLockReadOnly
Response.Write oRS("EMAIL_ADDRESS")
oRS.close oConn.close Set oConn = nothing Set oRS = nothing %>
this gives the error: "No value given for one or more required parameters".
what i would really LOVE is for someone to fill in whatever required parameter im missing, but more important i would like to understand whats going on. there are people who go through life dumb and happy once something "works", but i need to understand how and why its working. even if this code did work, im confused with the SELECT statement (no, i dont have much SQL experience aside from basic queries). what is the "r = Rnd" line doing in the middle of the querie? how am i ordering by r?? also, i dont have an indexed, primary "ID" field in this databae. is that ok for this code to work?
I want to take 3 records from a database. The selection must first take any record marked as priority and then random records (so there could be 3 priority records and no more or 1 priority and 2 random etc) My theory is to build a recordset filtered by records marked priority, and if there are less than 3, build a second recordset of all the other records. Questions 1, how can I select random records form the second recordset, without selecting the same one twice? 2, OR, could I write a sql statement which would randomly select 3 records from my table 3, Or is they a way I could write a query (view) in Access which would do the whole lot for me (select the priority records and then random records up to 3)?
I have read 10000 opinions on returning random records and I am more confused now that before I started. I have a small access db that will contain 20 or so rows with 3 or 4 columns. I like to return a set of 6 distinct rows and display the columns in html. I have seen response.write and loops but can't I throw the 6 random rows in a array and pull the data as I need it in the page? Examples?
I have this page where I want to display 3 random pictures in a vertical table. Each picture represents a record in an Access database. The field "picname" holds the name of the picture (e.g. "pic1.jpg", "pic2.jpg", etc). Each record has a unique ID. How do I go about selecting these 3 records? I want the pictures to alternate everytime someone enters the page or refreshes it. I found a couple of javascript options, but they only choose the picture from within a folder, and I need to be able to link the pictures to each record.I don't know if I made myself clear enough.
Now What i am trying to do is , when the first time is student is login,he wil be shown a random record from the question and his answered wil be stored in the Ans field of the student table with column separeated.
The he will be redirected to the same page with one new question.This question should not be in the Ans Field, and must be randomly generated.I am using this code.But this not working. Code:
[vbs] "SELECT * FROM Articles WHERE Category = 'Reviews' and SubCat = {RANDOM CATEGORY} LIMIT 5;" [/vbs]
Now, I think the last post on the thread I read said the guy could make an Array and just pick a random item out of that...and that makes sense in my case, listing all the Categories and then picking a random one.But, I don't know how to do it! I don't have much experience in arrays
i am currently working on an online test tool using ASP. Now, the questions would be generated randomly from a database(access), so two or more candidates will not have the same question. There will be one question per page. Now, i have successfully generated the radom questions from the database.
But i have a problem which is:
1. When i click the next link to go the next question, my code displays the question on the previous.
2. Also, when i click on the previous link to go back to the previous question my code changes the question from the previously answered to a new question. Code:
Im looking for a very simple and small script that will display 2 random records for a database, but i havnt found one yet. Can someone help me on this one?
I'm trying to create a portion of script that would select x (variable) number of random records from a table.
in PHP, I could do this pretty simply with a line like, "select * from table order by rand() limit x", but the solutions I've seen so far for asp and access involve things like 40 lines of code, selecting the entire contents of a database, creating temporary tables, etc.
I have been using this script which basically works fine, with on hitch. I populate a recordset from a database. Then, use the total number of records as a UBound.
I then want to display 9 random records. I get my 9 random images, but for some reason, if I do a sort by ID on the database, the lowest numbered ID file never comes up in the list. Here is my code: Code:
I have to develop an online quiz on my website. the site is developed in ASP. i have a access database of the questions, the multiple ans.s and the correct ans. every quest. has an unique id.
i want a way by which any 10 'unique' quests. will be selected from the database everytime an user takes the test.
I know there are plenty of threads relating to 'random' records, but non of the code samples seem to return random results each time I refresh the page; or don't show any results at all? The ID numbers for my recordset are not necessarily consecutive numbers (some items may have been deleted). I simply want to feature 2 or 3 random news teasers on my home page WHERE feature="yes". I guess I need to call 3 random id's, and keep looking until a record is returned? I would also like to change the number of 'teasers' displayed via another database table - I can do this later, but the code has to accommodate a flexible way to change how many records are returned.
Here's the Access table:
news (TBL): id title shortdescr longdescr feature
If you have a possible answer for me could you please provide sample code and spell it out clearly.
I Have searched the forum but have no solution to this problem.
I want to display my records in a random order. I loop through my records so I don't know how many records will be displayed. I dont want to count the records and then use the TOP statement. I'm looking for a better solution.
Set rs = Server.CreateObject("ADODB.Recordset") rs.Open SELECT test FROM testTable WHERE testId = 1, objConn Do While Not rs.EOF Response.Write "<b>" & rs("test") & "</b>" <- I want theese records to be displayed in random order rs.MoveNext Loop
Still working on my soccer database, I have a list of 100s of teams and want to give users various ways of accessing the information. One of those methods would be via a drop down box which would have
A-F G-M N-T U-Z
If a user selects a-f how could I write my sql statement so that it pulls out the relevant teams, in alphabetical order, that begin with the letters a-f?
I display work request records from a db table into a .html table dynamically by cycling through the db table until RS.EOF.
To the right of each record displayed I have two checkboxes, "chk_dev_accept", "chk_dev_sendnotif". These are the only editable items on the page.
"chk_dev_accept" is clicked by the developer to assign the work request to his/herself. "chk_dev_sendnotif" is clicked if the developer wants to notify the customer that the status of the job has changed (optional and automatic - I don't have a problem with this part).
Upon clicking the "Update Record" button, I want the records with the checkboxes clicked to update.
The db record fields that would be updated are: "dev_developer" (The developer that will do the job, read from a cookie) and "dev_proj_status" (changed to 'Assigned'). These two fields should update when the "chk_dev_accept" is clicked and form submitted. I want the developer to check as many records as he/she wishes.
My problem is I'm not sure how to code that <input checkbox....> tag, and then, how to take that checked value to select the appropriate records to update.
-- I have a database with user records (name, photo, etc. etc.)
I want to use asp to generate (on the homepage) a series of 4 randomly selected 'user records' from the database -- say just the headshot photo or name from the database.
In addition to the recordset being randomly generated (i.e. our of about 50 records, only records 4, 18, 23 and 26 are displayed) I need to MAKE SURE they are not duplicated (i.e. out of the 50 records, records 4, 18, 23 and 23 -- where the last two are duplicates).
Is there a way I can pull this off and how do I go about it exactly?
However, what I want to do is include a request.querystring("ID"), so that IF an ID is defined, eg ID=3, , it will display the relevant (not random) information. I've tried this every way I can think and get type mismatches, etc etc. It's probably really simple but I can't see it.