How To Choose A Random Record From A Database

ill have a database with 1 table and 3 fields:

ID FIRSTNAME LASTNAME

(the ID field will be the auto incrementing index)

there might be 10 records in the DB, there might be 10,000. i need to open the DB and randomly select a record (and then display the name, which i dont have a problem with)

how can i randomly select a record? im guessing id have to open a recordset and check the count to get the number of records, so lets say there were 100 records. i imagine i would have to generate a random number between 1 and 100....

View Replies


ADVERTISEMENT

Choose A Record

i have a database with one table... there are about 10-20 records in the table. i would need to create a page that displays a few descriptive fields of the records. just something like this.

ID NAME PRICE
1 type1 345
2 type2 567
3 type4 1000

just a simple list like this in a table, also each record would need to act as its own hyperlink, so when clicked on. using the primary key i presume, it loads another page specifically for that record. almost like a catalogue..if someone could please direct me to a few tutorials or online examples of this kind of procedure.

View Replies View Related

Random Record From DB

I have a DB with 10 items and an SQL statement:

"SELECT * FROM myTable WHERE Activate=true"

How do I make it so that every time the page refreshes it will display a random record?

View Replies View Related

Get Random Record

Is there a simple code I can use in order to get a random record from a access database in ASP ?

View Replies View Related

Random Record

I have an access database, and in a table is the field "names". There are over 100 different values in this field. I was wondering if it was possible to connect to the database and randomly select 1 of these names from the field and display it.

View Replies View Related

Select RANDOM Record

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.

View Replies View Related

Random Record Retrival

I want to create a record set for all the products in my database, i then want to randomly select some of them each time the page loads and display them, these have to change upon each refresh.

any ideas

my final problem i will post seperatly however, heres the score if any has any ideas.

ive created a product database of bikes, they have diferent sizes and colours. at the moment i am having to display each individual record. rather than having a single record and then on the detail page being able to have a dropdown menu or a choice of sizes there?

View Replies View Related

Random Record Selection

i have an access database with 5 records in and i need to show them in a random order every time the page is refreshed or reloaded. i've searched round and tryed no end of code but nothing seems to work.

i just need something really simple that selects a random feild from my DB. Sql = "SELECT * FROM tblmain ORDER BY RND()" - ive tryed this and it just shows the results in teh same order.

View Replies View Related

9 Random Records - Returns All But First Record In RS

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:

View Replies View Related

Random Record Selection Error

I'm trying to create a piece of code that randomly selects a record from a database (providing the record has not already been chosen for any of the previous 4 sections).
Here is my code:

View Replies View Related

Random Record With SELECT TOP Does NOT Work

<%
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?

View Replies View Related

Select Random Row In Database

does exist any command to get random row from target table in target database and then use this row ?

View Replies View Related

Random Database Results

I am using the following code to Query information from my db table. The problem I have is that it displays the whole table rather than displaying 5 random results by ProductID.

<%
objConn2.open strconn2
Set objRS2 = Server.CreateObject("ADODB.Recordset")
objRS2.Open "SELECT * FROM Products", objConn2

Do While Not objRS2.EOF
Response.Write ":: <a href=""productsDisplay.asp?ProductID=" & objRS2("ProductID") & """>" & objRS2("Product_Description") & "</a><br>"
objRS2.MoveNext
Loop
objRS2.Close
objConn2.Close
Set objConn2 = Nothing
%>

View Replies View Related

Random Database Records

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.

Is there any quick and dirty way of doing this?

View Replies View Related

Random Values From Database

Suppose I have a table named as tblfriends and there are 3 columns with several row. Column names are: name, email, phone

I want to pick 5 names randomly from the table each time my asp page refreshes. How can this be coded in classic asp?

View Replies View Related

Inserting Random Passwords Into Database

I have a ASP/vbscript program that generates random passwords. The problem is I need to insert those passwords into an Access database of 327 clients. I have the random password program generating the 327 passwords, but have had no luck inserting them. Code:

View Replies View Related

Random Quote From A Database Every 4 Days

obviously in standard asp. and i'm not even sure where to begin. I currently have it set up for a random quote every time a user refreshes the site. This was no problem. Any help or if you can point me in the right direction.

View Replies View Related

Generating A Random Code Which Is Not In Database

I am trying to write a script that generate random code which are not in database.

Things are ok on these points:

1. Generating a random code

2. Controlling whether it is in database.

For now, if the code is in database, it gives a message.

What I want the funstion do is to generate a code which is not in db?

How can id do this?

I write the code as reference.....

View Replies View Related

Selecting Random Records From Database How?

The following code should select the specified number of records randomly from the database .....

View Replies View Related

Fetch Random Database Table

There are 26 prizes available in a competition a client is running and he wants to be able to select these at random.

I thought the best way of doing this would be to construct a simple ASP page which displays 26 random records from the database.

The fields I wish to display are called name, email and address, and these are located in the table called Competition (this is an MS Access db).

View Replies View Related

Random Display Of Images Dynamicly From Database

I am trying to retrieve images from the database and display them in a random order. The order of the images is supposed to change each time page is refreshed.

Below is my code, I am using an array to store the images but the images are not displayed for some reason. Any help would be appreciated.

<% Dim rstResult
Dim strSQL
Dim img(100)
imgID = 0
set rstResult = Server.CreateObject("ADODB.Recordset")
strSQL = "sp_sel_TilesByType 'O'"
rstResult.Open strSQL, strConnect

set rResult = Server.CreateObject("ADODB.Recordset")
sSQL = "sp_sel_TilesByType 'O'"
rResult.Open sSQL, strConnect


if not rResult.EOF then

do while not rResult.EOF
response.write("hi")

imgID = imgID + 1
img(imgID) = "images/tiles/" & rResult("TileImage")
response.write(img(imgID))
rResult.movenext

loop
end if

if not rstResult.EOF then
intVendorID = 0
do while not rstResult.EOF


if intVendorID <> rstResult("VendorID") then
rndNumber = RandomNumber(imgID)
Response.Write "<p>"
Response.Write "<a href=javascript:popWin('tileview.asp?" & rstResult("TileID") & "','',1,1,1,1,700,600);>"
'Response.Write "<img src=images/tiles/" & rstResult("TileImage") & " border=0>"
response.write(rndnumber)
Response.write "<img src=img(rndNumber)>"
Response.Write "</a>"
Response.Write "</p>"
end if
intVendorID = rstResult("VendorID")
rstResult.MoveNext
loop
end if
set rstResult = nothing%>

View Replies View Related

Returning Random 10 Records Form A Database?

How can I do it?

View Replies View Related

Writing Array Of Random Numbers To A Database

I am trying to write an array of random numbers to a database. The array part is working fine, but when I go to update the dataabse, it inserts the last value of the array into all the fields in the database .....

Dim MyValue,sqlRandom
Dim arrayRandom(8)
for i = 1 to 8
Randomize
MyValue = Int((100 * Rnd) + 1)
arrayRandom(i) = MyValue
response.write "<p> Array Value:" & arrayRandom(i)

sqlRandom = "UPDATE CarParkDetails SET FreeSpaces = '" & arrayRandom(i) & "'"
Conn.execute(sqlRandom)

next

I can't see whats wrong!

View Replies View Related

What CMS To Choose?

What Content Mgmt Systems do forum members and ASP pros use?

I'm looking for something fairly sophisticated (WYSIWYG editor, user permissions, versioning, audit trail, etc) that doesn't cost an arm and a leg. It should be pure ASP, and (naturally) available with full source code.

View Replies View Related

Choose A Folder With ASP.Net

I want to allow a user to select a windows folder for reading. I have tried
to work it out without success. Can anyone help me out or point me in the
right direction. I am an experienced VB6 programmer but this is my first
ASP.Net project.

View Replies View Related

Can I Choose The Session ID ??

Is it possible to set the sessionID = value?

I am storing a shopping cart in a in a temporary table and with the sessionID identifying which items belong to the different users. Ideally I want to set it to a random GUID or number so it will make it very hard to guess the next session ID and gain access to another cart if they knew what they were doing.

Any ideas on how to set the sessionID value? Do I need to go that mush in to detail?

View Replies View Related

Choose Data From DB Randomly

i need to choose a data, randomly, in a database based n category (cat1, cat2, cat3, cat4, cat5, cat6). i only need to show 1 data of each category in the html page. kindly inform where to find a sample tuts for this.

View Replies View Related

Choose Oracle Version

I've just had a problem with an ASP page not connecting to one of our Oracle databases. It turns out that the web server has Oracle 8.1 and Oracle 9.2 installed and that my
ASP page was trying to connect with Oracle 8.2. The TNSNAMES.ORA file for this version of Oracle is not maintained and did not have the correct entry I need.

Is it possible to force my ASP pages to use Oracle 9.2 until the migration is complete and Oracle 8.1 is removed?

My connection string looks like this:

Session("PROVIDER") = "Provider=OraOLEDB.Oracle;Data
Source=ht;User Id=" + Request.form("username")
+ ";Password=" + Request.form("password")

View Replies View Related

Choose And Enter Value One Optional

I like to validate 2 textboxes. Users ken choose to enter either one. Therefore if nothing is entered for both, im suppose to prompt him to enter at least one. If he enters value into both txt boxes, I'll prompt him again. Dunno to post this here or @ javascript forum.

View Replies View Related

Choose Image From The Server

i have a folder contain many images in a server, i got to do a web application allow user to choose image the from the folder in the server to be their signature, may i know how to get into the image in the folder on the server?because from what i know i can do a textfield to browse to the file in my local machine, but how do i browse throught the fiel in the image folder that i mention?

View Replies View Related

Choose Recordset In Stored Procedure?

I have a SQL 2000 stored procedure with several recordsets. Is there a way to query a specific recordset in a stored procedure, or will I have to loop through each recordset?

View Replies View Related

Add Record On The Database

i use access database and made add record page and it is added on the database then i made another page to add on another table on the same database it is not working i donot know why,and the problem from me or from the server setting???

View Replies View Related

Get Record From Database

i try to display record from oracle to form format. all the records will get from INST_REC table which have fields such IID,SN,SID and STN. how can i write the html statement to let the record display in the below text field.

i hv write the html code for this, but got error.i think the problem is in the value ="<%rs("IID")%>". what should i write for the value part in order to get record from oracle?

<TDvalign=center><INPUTTYPE=textNAME="ASSET_NO"value="<%rs("IID")%>"ID=Text3></TD>

this is the sample of form that being use :
ID : SN :

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved