Adding a numeric function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tegwin
Forum Newbie
Posts: 8
Joined: Fri Nov 27, 2009 5:19 am

Adding a numeric function

Post by tegwin »

I have a function simlar to this: "getUserDetails($userID)" That returns an array of details for that given user.

User ID is a 4 or 5 digit number.

What I want to do is write some code that runs the "getUserDetails()" function repeatedly but each time it does it with asequentially different user ID... so numerically starts at 0001 and runs up to 20000

The returned data for each user will then be entered into a database table before moving on to the next user ID and so on until it reaches 20000

Can anyone suggest a way of doing this? :dubious:
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: Adding a numeric function

Post by Weiry »

Code: Select all

$yourNumber = 20000;
for($i=0; $i <= $yourNumber; $i++){
    addUserDataToDatabase(getUserDetails($i));
}
something like that?
where:
$yournumber = the number of iterations you want to do ie. 20,000
addUserDataToDatabase() = takes a user data array to add into database
getUserDetails() = takes user ID and returns user data array

You would need to create the addUserDataToDatabase() function of course.
tegwin
Forum Newbie
Posts: 8
Joined: Fri Nov 27, 2009 5:19 am

Re: Adding a numeric function

Post by tegwin »

That seems to work ok thanks :) Takes a long time to complete the execution of all 6000 entries though.... I cant change the execution limit on the page so looks like I i will have to do 500 at a time :)
roders
Forum Commoner
Posts: 68
Joined: Tue Oct 20, 2009 9:29 am

Re: Adding a numeric function

Post by roders »

if its stopping because of the execution time then add the begining of your page add

Code: Select all

ini_set('max_execution_time', $limitofexectime);
change $limitofexectime to whatever you need it to be in seconds of course.
tegwin
Forum Newbie
Posts: 8
Joined: Fri Nov 27, 2009 5:19 am

Re: Adding a numeric function

Post by tegwin »

Sadly ini_set(); is disabled on my system... and I do not have the ability to switch it on. :banghead:
Post Reply