Any PHP masters on here?
Discussion
Have a bit of an issue... wonder if anyone here has any ideas?!?
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 a sequentially 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 with php? :dubious:
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 a sequentially 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 with php? :dubious:
for ($i=0; $i<20000; $i++)
{
$userDetailsArray = array();
$userDetailsArray = getUserDetails($i);
// Do the database insert, e.g.
$q = "INSERT INTO users (user_id, user_name) VALUES (" . $userDetailsArray['id'] . ", '" . $userDetailsArray['username'] . "')";
$r = mysql_query($r);
}
{
$userDetailsArray = array();
$userDetailsArray = getUserDetails($i);
// Do the database insert, e.g.
$q = "INSERT INTO users (user_id, user_name) VALUES (" . $userDetailsArray['id'] . ", '" . $userDetailsArray['username'] . "')";
$r = mysql_query($r);
}
Edited by evenflow on Wednesday 31st March 10:29
what does the function do? It might be far faster to replicate the functionality than it is to use a for loop, e.g.
if getUserDetails() simply runs a SQL statement and converts it into an array and then gives it to the return, why not:
insert into <NEWTABLE> (`<FIELDS OF NEW TABLE>')
select <FIELDS FROM OLD TABLE WHICH MATCH NEW TABLE>
from <OLDTABLE>
where userid > 0
and userid < 2000
Of course, depending on what you need to do, you could always use a Database view to prepare the data from the raw table...
if getUserDetails() simply runs a SQL statement and converts it into an array and then gives it to the return, why not:
insert into <NEWTABLE> (`<FIELDS OF NEW TABLE>')
select <FIELDS FROM OLD TABLE WHICH MATCH NEW TABLE>
from <OLDTABLE>
where userid > 0
and userid < 2000
Of course, depending on what you need to do, you could always use a Database view to prepare the data from the raw table...
Good call Evanflow
That seems to work a treat!
Bit of a bugger I can only do 500 Id's at a time... the server seems to have a very short time limit set for page excecution... and sadly I cant change that!!
Looks like I will have to call the same page multiple times to load up chunks of data in different ranges... Not the end of the world
@American... I dont have access to the underlying database which is a pain.. hence why I am trying to create my own database
That seems to work a treat!Bit of a bugger I can only do 500 Id's at a time... the server seems to have a very short time limit set for page excecution... and sadly I cant change that!!
Looks like I will have to call the same page multiple times to load up chunks of data in different ranges... Not the end of the world

@American... I dont have access to the underlying database which is a pain.. hence why I am trying to create my own database

Edited by tegwin on Wednesday 31st March 11:58
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff



