create folders and capture results in html file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

create folders and capture results in html file

Post by gurjit »

hi

I have a script which

- queries the database for records in cities

what I want to do is:

- create unique folders for each city on the server
- create a index.html page for each folder

so for example:
if I had 5 citys (A,B,C,D,E)
Each city had 10 records.
I would have 5 folders named A,B,C,D each with its own index.html file and 10 results

How can I achieve the snapshot of results?
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: create folders and capture results in html file

Post by Zoxive »

The most common way would to use url rewriting.

Since you have all of the data in the database,

Take this example.

.htaccess file

Code: Select all

RewriteEngine On
RewriteRule ^city/([^/\.]+)/?$ city.php?city=$1 [L] #Route everything after /city/ that does not have a period
 
city.php

Code: Select all

<?php
$City = !empty($_GET['city'])? $_GET['city'] : NULL;
 
echo $City;
 
// Get Data from database..
Then go to yourserver/city/cityname and you will see `cityname` echoed. Using this you can then select the data from the database instead of creating folders and files.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: create folders and capture results in html file

Post by RobertGonzalez »

Do you really want to create that many folders and files? What happens after 5,000 users have run this script? How do you maintain that?
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

Re: create folders and capture results in html file

Post by gurjit »

Just too confirm:

step 1: create a folder in the root /city
step 2: create the .htaccess file in the root
step 3: in the /city folder create the file city.php with my query and record results, and page layout. I believe this page will get displayed when a city is searched

What will happen. If users are searching on "aber" and then "aberd" - will this create two folders?

The reason for doing this is so we can get indexed better on google. I have noticed a lot of sites indexed have folder structures for cities i.e. they have folders like birmingham/index.html, leeds/index.html, manchester/index.html. If you have any other idea of doing this I would be interested.

Thanks
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: create folders and capture results in html file

Post by RobertGonzalez »

You do not need to literally make files and directories for each request. Simple URL rewriting can handle that for you (and I think it was already suggested in this thread). If you are on apache you can use mod_rewrite to make some URL rewriting rules so that all requests for http://mysite.com/city/aber/ will make to index.php?q=city&term=aber.
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

Re: create folders and capture results in html file

Post by gurjit »

Since the requests are not as folders on the server, when the search engine spider crawls the site it will not find these folders and not index them
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: create folders and capture results in html file

Post by RobertGonzalez »

The rewrite rules will handle that for you. That is how things are done. Really. Imagine a high traffic site that has millions of "pages" of data. Do you honestly think they make an actual hypertext page for each one?
Post Reply