For some reason I am just dumb with arrays… I cannot figure them all the way out… All I want to do here is read a folder and get all the folder names inside of that folder and insert them into a mysql db. Now the db part isn’t my problem. Its handling this array. I did something similar in an earlier project, and now I cannot figure out how to modify it to work here.
<?php
$main_folder = 'C:/Users/Oval Office/Music/';
$folders = glob($main_folder, GLOB_ONLYDIR);
$artists_names = array();
foreach($folders as $folder){
$artists_names[] = preg_split('/(.+)\s(\d+)/', str_replace($main_folder, '', $folder), -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
}
$values = array();
foreach($artists_names as $pair){
$values[] = "('".$pair[0]."')";
}
$query = 'INSERT INTO artists (title) VALUES '.implode(',', $values);
$result = mysql_query($query);
echo ($result) ? 'Inserted successfully' : 'Failed to insert the values';
?>
The Title Is Just Blank…
Thank you pekka for stearing me in the right direction, post it as a answer so I can give ya some rep.
I think the wild-card is missing.
Try this: