I'm pretty close but im running into some huge problems when its executed that I cannot explain.
these are my steps
1.) use scandir to load the names of all the folders into an array.
2.) lookup the RID of that record where SID in the database = SID of the folder
3.) change folders name to RID.
4.) change code to lookup records based on RID instead of SID
Now in my code im going as far as just printing "Will change folder from [SID] to [RID]" displaying the actual names, and a line break, which shows the new folder names for all 5000+ records.. I havnt implemented the code to actually change the folder names... yet
When I go to echo the array elements with a while and a counter, all 5000+ are listed fine in order... however when I do the database lookup during the while and say "echo 'will change folder from [SID] to [RID]' <br>"; I get some REALLY funky output...
Code: Select all
$folders = scandir("records/");
// Get number of folders
$counted = count($folders);
echo "there are $counted folders <br><br>";
$counter = 0;
while($counter < $counted){
//=================================>
// Get connection to database and
// retreive the RID's of each of
// these folders names. The folders
// are named after the records SID.
//=================================>
//======= Get Connection to DB ========>
$link = functions::getConnection();
//=====================================>
$query = "SELECT RID FROM students WHERE SID = " . $folders[$counter];
$result = mysql_query($query);
while ($row_data = mysql_fetch_array($result))
{
$RID = $row_data['RID'];
echo "Need to change " . $folders[$counter] . " to " . $RID . " <br>";
}// END INNER WHILE
//========= Close Link to DB ==========>
mysql_close($link);
//=====================================>
$counter++;
}// END WHILEas when i normally echo the $folders[$counter] I get a neatly ordered list of all of the folder names....
Here's what my output looks like when i try to execute the code above...
As you can see, the same SID gets repeated multiple times with different RID's each time, and there is no order to the RID's it starts to jump around a lot.. the SID's repeat multiple times as well.. Keep in mind the first # is the name of the folder and the second number after "to" is what the folder will be renamed to.Need to change 000-00-0000 to 1
Need to change 000-00-0000 to 2
Need to change 000-00-0000 to 3
Need to change 000-00-0000 to 4
Need to change 000-00-0000 to 5
Need to change 000-00-0000 to 6
Need to change 000-00-0000 to 7
Need to change 000-00-0000 to 8
Need to change 000-00-0000 to 9
Need to change 000-00-0000 to 10
Need to change 000-00-0000 to 11
Need to change 000-00-0000 to 12
Need to change 000-00-0000 to 13
Need to change 000-00-0000 to 14
Need to change 000-00-0000 to 15
Need to change 000-00-0000 to 5296
Need to change 0041573124 to 424
Need to change 0311151956 to 1052
Need to change 0699009267 to 1238
if it was working the RID's would number from 1 - 5000+ neatly...
What is going wrong with my code, is it something obvious? Is it a php bug? Is it my computer???