Note that there are some explanatory texts on larger screens.

plurals
  1. PORead A Folder And Split Sub-Folder Names Into MySQL Inserts
    primarykey
    data
    text
    <p>I have a folder named "Comics" and sub folders in that directory with the names of comics + the issue</p> <p>Example:</p> <pre><code>/Comics &lt;-- Main Folder /Amazing Spider-Man 129 &lt;-- Sub Folder /Hellblazer 100 &lt;-- Sub Folder /Zatanna 01 &lt;-- Sub Folder </code></pre> <p>Now what i want to do is scan the Comics directory and output each folder name as a mysql insert query. The actual folder name needs to be seperated as "Comic Name" &amp; "Comic Issue".</p> <p>Example Query</p> <pre><code>mysql_query("INSERT INTO comics (name, issue) VALUES ('Amazing Spider-Man', '129')"); </code></pre> <p>I got this far and now i want to add a query check to see if the comic exists or not.</p> <pre><code>&lt;?php $main_folder = 'K:/Comics/'; // should be K:\Comics\ but I changed it because of the highlighting issue $folders = glob($main_folder.'* [0-9]*', GLOB_ONLYDIR); $comics_series = array(); foreach($folders as $folder){ $comics_series[] = preg_split('/(.+)\s(\d+)/', str_replace($main_folder, '', $folder), -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); } $values = array(); foreach($comics_series as $pair){ $values[] = "('".mysql_real_escape_string($pair[0])."', '".((int) $pair[1])."')"; } $check_query = mysql_query("SELECT * FROM comics WHERE name='".$values[0]."' AND issue='".$values[1]."'"); if ($check_query == '0'){ $query = 'INSERT INTO comics (name, issue) VALUES '.implode(',', $values); $result = mysql_query($query); echo ($result) ? 'Inserted successfully' : 'Failed to insert the values'; } ?&gt; </code></pre> <p>is that the right format for the query_check?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload