Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

random number generator 1

Status
Not open for further replies.

spookie

Programmer
May 30, 2001
655
IN
I am using mt_rand() for generating random number for dynamic banner display purpose.
the banner table has column id which is auto increment.

now i have to delete some banners from the database thru admin module..so naurally if that id which is generated by mt_rand is not found in table, it will show that empty box..

i am not very keen to change php code which is displaying the dynamic banner.
so wht is the simplest way to get out of it..
may be to update the ids itself after deleting the particular banner??
eg. if row with id=2 is deleted, id=3 will be updated to 2,
4 to 3 and so on..

thanks in advance

spookie --------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Updating the IDs is probably not the best route.

If it has one available, I would use the database servers's random function to pull the records.

For example, in MySQL something like:

SELECT columnname from tablename order by rand() limit 1

will pull one record at random from the table. Want the best answers? Ask the best questions: TANSTAAFL!
 
Thanks sleipnir214!!

Acutally i was not keen on modifying the php code that generates the number(thats included in number of pages) but i think i will have to do that..

regards

spookie

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top