ValkR Posted August 22, 2011 Share Posted August 22, 2011 I've got: /A/index.html /A/1/index.listing /A/2/index.listing /A/3/index.listing In index.html, I've got the following PHP code: <?php $files = glob('./*/*.listing'); foreach ($files as $file) { include $file; } ?> As you can see, what PHP code does is include()'s all the index.listing files. I then create a clone of the A directory and alter the HTML in the .listing files so can tell the difference between A & B when they render: /B/index.html /B/1/index.listing /B/2/index.listing /B/3/index.listing The issue I am having is "/B/index.html" is ()including the .listing files from the /A/*/ directory, when it should be including them from the /B/*/ directory. I can't understand why this is happening and hoping someone could shed some light on the issue? Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted August 22, 2011 Share Posted August 22, 2011 No one else pointed out that you are using double wild cards from the root? You are actualy telling the script to look in every subfolder of / so it's guarenteed to pull A & B, if you run the A script it will also pull in A & B. You will need to code some conditional logic to determin which you want, or change it to be ./A/*.listing and ./B/*.listing for the appropriate index.php files. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted August 22, 2011 Share Posted August 22, 2011 Not sure if I under stand 100%, but give this a try: <?php for($i = "A";$i <= "Z";$i++){ foreach(glob("./$i/*.listing") as $file){ require_once $file; } } ?> Quote Link to comment Share on other sites More sharing options...
ValkR Posted August 22, 2011 Author Share Posted August 22, 2011 No one else pointed out that you are using double wild cards from the root? LOL mate, no one has said anything!! You are actualy telling the script to look in every subfolder of / so it's guarenteed to pull A & B Doesn't the "." infront of the directory state 'from this directory!"? If so, A and B would be a parent directory, so PHP shouldn't even know they exist as the code be executed from within. Not sure if I under stand 100% You do mate and I see what your doing. Very very very smart!... but it didn't work. To brief you a little what I am doing.. I am starting an online store website. A = product category 1 = product *.listing is a listing file I have made - index.listing. When one visits the product category page, I want it to show all the products, so I have include() all the all the listing files, so it builds a list of available products. The .listing files are just a few lines of HTML - an image and some text with a hyperlink to the products own page, which would be /A/1/index.html. This ways awesome because it means everything related to the product is in a single directory. I don't like central databases like would be found in MySQL. What this means is all I have to do is drag and drop a directory in or out of the A directory. Eventually I am going to make a payment system... Once payment is confirmed, a little script will run that simply moves the product directory outside my www directory, such as to a directory called /sold. Lets say a customer returns the item, all I have to do is move the product directory back into my WWW directory in the relative product category folder and there you have it. Pretty awesome hey! I still face the problem of getting this listing system working though. :S Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted August 22, 2011 Share Posted August 22, 2011 ./ means the current directory from which php is executing from. So, if this script is in the root directory of the web server "A", "B", "C" etc would be child directories according to your glob. Also, what happened when my code ran? no results? if that is the case, your glob path is wrong. Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 22, 2011 Share Posted August 22, 2011 When one visits the product category page, I want it to show all the products, so I have include() all the all the listing files, so it builds a list of available products. The .listing files are just a few lines of HTML - an image and some text with a hyperlink to the products own page, which would be /A/1/index.html. This ways awesome because it means everything related to the product is in a single directory. I don't like central databases like would be found in MySQL. What this means is all I have to do is drag and drop a directory in or out of the A directory. Eventually I am going to make a payment system... Once payment is confirmed, a little script will run that simply moves the product directory outside my www directory, such as to a directory called /sold. Lets say a customer returns the item, all I have to do is move the product directory back into my WWW directory in the relative product category folder and there you have it. Pretty awesome hey! Awesome? Not really. This is the exact type of scenario where a database is needed. Replying upon file copy/move procedures to run your site is going to lead to problems. It's understandable if you are perhaps intimidated by databases because you are not familiar or don't have a lot of experience. But, that IS the solution you need. Quote Link to comment Share on other sites More sharing options...
ValkR Posted August 22, 2011 Author Share Posted August 22, 2011 Never mind, there was nothing wrong with the code. It was another problem. The code works. I don't know about your code because actually never ran. The product page with all the different categories like A B C D... well, each category was hyperlinking to A, It took me 30 hours to notice that. I am really dissapointed in myself, well, not really. This is my first few days of PHP, I was just so focussed on it, forgot I can still make mistakes in HTML. Thanks for your help mate, your help has not gone in vein, believe me! You are right about the whole point of database, but I do like my setup better and even if I didn't I would stick with it because I don't have time to learn one. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.