Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 14-01-2009
Member
 
Join Date: Oct 2008
Posts: 47
Randomize mail from MySQL database

Including this script does not work.
I get the value -1 on Rand_nr and Number.
Why it nit working. I have read a lot on this...still
Code:
strSQL = "SELECT lopnr, namn, enamn FROM tblTest" Set Rs = objConn.Execute(strSQL) If Rs.EOF Then Response.Write "Inga poster att slumpa ?n.." Rs.Close : Set Rs = Nothing Else With Rs .Close .Cursortype=3 .Open End With Antal = Rs.RecordCount Randomize Rand_nr = Int(Rnd * Antal) Rs.Move Rand_nr Response.Write ""&Antal & "" Response.Write ""&Rand_nr & "" Response.Write " "&Rs("id")&". "&Rs("namn")&", "&Rs("enamn")&" " Rs.Close : Set Rs = Nothing End If
Reply With Quote
  #2  
Old 14-01-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: Randomize mail from MySQL database

Code:
 Else With Rs .Close .Cursortype=3 .Open End With
Are you really closing the Record Set to open it again?
Can not bring Cursortype directly or use getRows instead and get number of responses then?
Reply With Quote
  #3  
Old 14-01-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: Randomize mail from MySQL database

Why not use rand () in mysql instead of ASP? What I mean is that you should ask the database to return what they want, instead of downloading everything and then manually do anything half hitch filter.

select ID, Name, rand () AS random from table1
order by rand ()
Limit 1

This always gives a single post in response, and it is that at precisely the moment has the smallest value in the "coincidence".

(Although not 100% correct, as the rand () value is in the SELECT statement has no meaning, you need not even enter it. That's the ORDER BY uses as it is interesting.)
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Randomize mail from MySQL database"
Thread Thread Starter Forum Replies Last Post
How to connect PHP to mySQL Database Nathen Tips & Tweaks 2 17-07-2011 03:49 AM
Manipulating MySQL database using PHP blueprats Guides & Tutorials 1 30-04-2010 04:29 PM
How to speed up the MySQL database Kalanidhi Software Development 5 27-02-2010 01:33 AM
Mysql Error : Can't connect to local mysql server through socket ' var lib mysql mysql.sock' 2 roshan45 Software Development 3 07-11-2009 09:36 PM
Restoring MySQL database Sean J Software Development 5 18-02-2009 01:46 PM


All times are GMT +5.5. The time now is 04:53 PM.