0

I have a "New Employee" script, that when you enter the details it creates a folder according to their username, using mkdir, this all works fine,

I now have managed to import 200 entries into my DB from a spreadsheet, but I need to create a folder for all the people now in the database, I was about to do it manually, then realised, I could grab all the usernames from the DB and loop through each one creating a folder?

can someone help?
thanks

3
Contributors
9
Replies
11
Views
5 Years
Discussion Span
Last Post by websponge
0

How do I do it? I am rubbish with the for each loops! I dont know how to write the statement, I can do the SQL to grab all the usernames, but then what should I do? I assume its a for each mkdir($username) or something? thanks

0

Look at the code from your first thread 11 months ago. The loop is there, use it. Inside the loop you can do the mkdir.

0

Ive read thogh that , but it doesnt really help me in this case, how does the below look to you please?

$username= "select * from training";
$results = mysql_query($username);
while($row = mysql_fetch_array($results))
{
mkdir($row[username]);
}
0

didnt work with this code:

<?
$con = mysql_connect("localhost","root","");
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("training", $con);
$sql = "SELECT * FROM servicedesk";  
$result = mysql_query($sql);  
    while($row = mysql_fetch_array($result))
    {
    $thisdir = "../data/";
    mkdir($thisdir . $row["username"]);
    echo $row["username"];
    }
?>
1

Does the dir have write rights?

Just curious. This is a difficult one for maintenance. Creating a new folder for everybody now - ok. What happens when you add new users? To prevent problems with existing dirs?

$thisdir = "../data/";
while(...){
    $path = $thisdir . $row['username'];
    if (file_exists($path)){
        continue;    
    }else{
        mkdir($path);
    }
}

Check the mod status of the data directory. You may need to change it. Are you able to create a directory under it by a different script (not using the username)?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.