Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6137215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:41:53+00:00 2026-05-23T17:41:53+00:00

I have a folder named Comics and sub folders in that directory with the

  • 0

I have a folder named “Comics” and sub folders in that directory with the names of comics + the issue

Example:

/Comics <-- Main Folder
    /Amazing Spider-Man 129 <-- Sub Folder
    /Hellblazer 100 <-- Sub Folder
    /Zatanna 01 <-- Sub Folder

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” & “Comic Issue”.

Example Query

mysql_query("INSERT INTO comics (name, issue) VALUES ('Amazing Spider-Man', '129')");

I got this far and now i want to add a query check to see if the comic exists or not.

<?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';
    }
    ?> 

is that the right format for the query_check?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:41:54+00:00Added an answer on May 23, 2026 at 5:41 pm
    <?php
    $main_folder = './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])."')";
    }
    
    $query = 'INSERT INTO comics (name, issue) VALUES '.implode(',', $values);
    $result = mysql_query($query);
    echo ($result) ? 'Inserted successfully' : 'Failed to insert the values';
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a folder ~/ConfigurationDirectory. The sub-folders within this folder are named as follows
I have a folder named repository in my admin folders. This folder holds 2
I have a folder named import at my root directory where the public folder
I have a content folder which is full of other sub-directories named in the
I have a file watch directory named FileWatch C:\Users\MyFolder\FileWatch\Test The FileWatch folder is the
In the /data directory of solr, suppose, I have three folders named as index,
How to exclude files from src/main/resources, for ex : I have a folder named
I have a folder in my app named Files. I would like to display
I have a file named configuration.xml which resides in classes folder of my WEB-INF
In my Values folder for my project, I have a string array named currency_avatar.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.