Returning Random 10 Records Form A Database?
How can I do it?
View RepliesHow can I do it?
View RepliesI'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.
Is there any quick and dirty way of doing this?
The following code should select the specified number of records randomly from the database .....
View Replies View RelatedI am trying to have a form that has multiple records on it and the user can check a box on which ones to add to the database. I created the form but cannot get the fields to enter into the database.
View Replies View RelatedI have a seach function and I need to be able to only return records that begin with numbers.
SELECT * FROM [Tbl_Table] Where name LIKE '0-9%'
I'm back with the same code, which works fine, except for when i ad the block of code that i noted...i get the error message:
ADODB.Field error '800a0bcd'
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/test/testbasket.asp, line 72
which is referring to the strSurvID=adoRSWEBtest4(0)
i know that the query above that is supplying webtest4 with its where check is returning a value. when i take out the noted block of code, the page works fine, and emails all information, including the value that is being checked for in webtest4. Code:
I have a project where i have to use an html asp application form to insert records into an sql database. My problem is finding resources online to practice with to learn, i have basic knowledge of ASP and have attended the microsoft 1 week course on Administering a 2000 SQL Database and i have designed a few small sites so i know html and javascript. I have the database side covered its just the VB code to take the form values and post them to the sql database.
I was wondering if anyone could point me in the right direction of sample codes to play around with as i cant seem to find any which relate to this project.
I just want to return the number of records in a database:
<%
Set cn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "SELECT COUNT(*) FROM alumni_baby"
cn.Open ("dsn=mssql;database=web;uid=aaa;pwd=aaa;")
rs.Open sql, cn
%>
<% Response.Write (sql) %>
But that spits out the sql statement, not a number. What am I doing wrong?
I'm trying to insert mutiple records into my database when the form is submitted.. My form has 4 textfields; serial1, price1, serial2 and price2.
I would like to insert serial1 and price1 as one record, then serial2 and price2 as the second record. I know some sort of loop has to be used to achieve this but i'm new to this and I don't know what to do...
I tried to do it with dreamweaver but it does not seem possible and the dreamweaver code seems really complicated I've only been able to insert only the first row(serial1,price1).. since I only have 2 fixed rows I guess what I need to do is to get dreamweaver to do it twice in a loop. Code:
I have a table that contains all of the function permissions within a given application. These functions are different sections of a site and each has its own permissions (READ, WRITE, UPDATE, DELETE) which are controlled by a web frontend and the table
records are manipulated to control the permissions. Code:
How does one return records in a recordset based on a time/date field. If todays date is 8/25/04, how could i return all those records from 8/25/04. Mind you, i have long date format ex. "8/25/2004 4:46:45 pm"
I dont want to user a form for this i simply just want these time- sensative records to be returned in the recordset .
I have a .asp page which includes "connTest.asp" which includes "adovb.asp" which includes all ADO constants definition, as mentioned earlier, if the adSomeLiteral=SomeValue constants didn't load the correct value I would get a RUNTIME Error(so constants IS NOT the problem),
the connection is setted up correctly, the command and parameters are created succesfully, the store proc works fine since I tested with ALL cases from Query Analyzer, even I tested the store proc from ASP environment, I call the SP as follow: Code:
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 know how to generate random record from a database, the problem i need to overcome is like this:
1.If the user refreshes the page is a way i can control the randomized data from not repeating itself on display?
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.
View Replies View RelatedI am doing a simple program which display random records to students.The student table has the following fields(Access Database) Code:
1.Studentid-Number
2.Studentname-Text
3.Class-Text
4.Ans-Text
and Question table as
1.Questionid-Number
2.Questions-Text
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:
Here's what i need:
[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?
View Replies View Relatedi want to select some records from my database by random. i want also to set a limit (limit=9).
View Replies View RelatedI 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?
Do you have any idea about weighted random records ? (for MSAccess AND SQL Server) Also can I get weighted random records just by SQL Language ?
View Replies View RelatedI have a tough question that i ca't get over it for all the day.
I have two different news tables. I can't get any of them and list.
Bu i want to do something different. I want to get both and randomize them and list them.
for example,
1. news (from the 1st db)
2. news (from the 2nd db)
etc.
is that possible, because i couln't find any solution for this.
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
Anyone has a solution to this problem?
I need to pull five records randomly from a database, and display them on a web page. These need to change weekly.
Is there a way to do this in ASP?
I have a form page a user needs to fill out. I want to be
able to send the user back to the form once it is
submitted and an error in processing occurs, for example
if they have an illigal charcter in the form somewhere.
The whole form wouldn't need to be retyped, just the
field in question.
How can I send the user back to the form they just
submitted to correct an entry?
I am trying to setup a form in Dreamweaver where I have a list box (Car Batteries, Antifreeze, Paint, etc.)
How do I setup the page up so that when an item is selected and they hit the submit button it will send them to another page returns just the information from that item on the database and not the entire database?
I'm trying to pull the last 5 records from my database.
<% j=5
rs.MoveLast
While ((j>0) AND (NOT rs_article.BOF))%>
''Execute HTML and data insertion here
<%rs_article.MovePrevious
j=j-1
Wend%>
Everytime I attempt to run this code, I recieve an HTTP 500- Internal Server Error. It tells me no more than that. I know that my connection settings are OK because when I move forward through the database (first five records), the code executes without error. And yes, my Cursor type is Dynamic.
Alternatively, I would also like to know how to add new recordset to the beginning of a database rather than the end.
What is a faster/better coding practice?
Method 1:
Code:
Sub myFunction(byRef x)
x = x + 1 ' do something with x
End Sub
x = 7
myFunction(x)
response.write x ' shows 8
Method 2:
Code:
Function myFunction(x)
myFunction = x + 1 ' do something with x
End Function
x = 7
response.write myFunction(x) ' shows 8
Also discuss considerations when there are more than one variables that need to be changed.