Welcome Guest, Not a member yet? Register   Sign In
replacing mt_rand code with CI code.
#1

[eluser]jim-_-[/eluser]
Right now I use 7 mt_rand's to generate ID values, I used these to generate random links (ads for my other content). But I use non-CI-PHP mixed in with the CI app as I'm not very good yet, is there a helper or plugin for this?

Right now I don't have code that checks if the ID is valid and it's a hassle so a plugin that includes that function would be preferable.

[code]<?
srand(time());
$id_a = (mt_rand(31,678)
#2

[eluser]Cristian Gilè[/eluser]
There is nothing wrong to use native PHP functions inside your CI apps. For repetitive tasks it is a best practice use an helper or create a validation rules inside your extended form_validation class.

Cristian Gilè
#3

[eluser]jim-_-[/eluser]
Thank you so much, I now have validation and clean urls for the randoms Smile
#4

[eluser]n0xie[/eluser]
Why are you randomly generating id's ? Wouldn't a primary key or the use of uniqueid() solve your problem?
#5

[eluser]jim-_-[/eluser]
[quote author="n0xie" date="1294852377"]Why are you randomly generating id's ? Wouldn't a primary key or the use of uniqueid() solve your problem?[/quote]

If I'm understanding function of uniqueid() its for generating IDs for storage in the database ? What I'm doing is getting random entries that are already in the database to be put on a page via thumbnails with info, stuff to get the guest to click on through.




Theme © iAndrew 2016 - Forum software by © MyBB