replacing mt_rand code with CI code. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: replacing mt_rand code with CI code. (/showthread.php?tid=37492) |
replacing mt_rand code with CI code. - El Forum - 01-11-2011 [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) replacing mt_rand code with CI code. - El Forum - 01-11-2011 [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è replacing mt_rand code with CI code. - El Forum - 01-11-2011 [eluser]jim-_-[/eluser] Thank you so much, I now have validation and clean urls for the randoms replacing mt_rand code with CI code. - El Forum - 01-12-2011 [eluser]n0xie[/eluser] Why are you randomly generating id's ? Wouldn't a primary key or the use of uniqueid() solve your problem? replacing mt_rand code with CI code. - El Forum - 01-12-2011 [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. |