faqts : Computers : Programming : Languages : PHP : Database Backed Sites : MySQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 11 people (36%) answered Yes
Recently 1 of 6 people (17%) answered Yes

Entry

How can display multiple random database rows formatted as URL,IMG,ALT TAG?

Sep 13th, 2000 16:37
Narendra Jain, Ted Hattemer,


You have to use the mt_rand function. 
mt_rand(min, max) uses a random number generator with known 
characteristics, the Mersenne Twister, which will produce random numbers
that should be suitable for seeding some kinds of  cryptography (see the
home pages for details) and is four times faster than what the average
libc provides. 
1. Get the maximum rowid (uniqid) in your database.table into id_max.
2. Initialize the seed for random number generation (mt_srand()).
3. l_rowid=mt_rand(1,$id_max)
4. l_result=mysqlquery($mydata1, "select * from user_table where uniqid
= $l_rowid)
5. Process l_result the way you want to i.e. format it into URL, IMG,
ALT TAG using printf().
6. Repeat steps 3 thru 5 as many times you want to process / generate
random number of rows.
Hope this helps...