开发者

What is the best/easiest method of creating a site from mysql tables and PHP? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

I am new to PHP and this will be my first site using PHP and MySQL... please help me with my issue.

Basically, I am beginning to create a site from scratch where there are 10 states and 8 regions in each state. I need to make pages for each state (10 pages) and pages for each region (80 pages).

Furthermore, the pages cannot be named:

example.com/state.php?state=New%20York

There are specific filenames (slugs) in the states table and also the regions table.

The urls will end up looking like this:

example.com/new-york-something.php

As far as the regions for each state, they will be placed into "state directories" which will be the same as the state filename.

example.com/new-york-something/br开发者_StackOverflow中文版onx-ny-something.php

I get how to make the information show up on each page, the only part I need direction with is how to decipher what type of page it is based on the url or another way to have the pages generated.

What is the most basic, simple method of doing this? I am not asking for anyone to do this for me, I am looking for guidance so I can efficiently learn and do this on my own. Your help is greatly appreciated.


You will want to get familiar with mod_rewrite. It is an Apache module that will help you transform urls like this:

example.com/newyork/bronx

into:

example.com/page.php?state=newyork&region=bronx

Page.php will then load, parse the url variables, and generate the correct page for your visitors, all while keeping the url friendly.

A great introduction to mod_rewrite can be found at http://www.workingwith.me.uk/articles/scripting/mod_rewrite, or just by googling mod_rewrite.


Honestly this is quite a large question, but i will try my best to hit a few key points.

About the "slugs", easiest method would be using Apache's mod-rewrite for url-rewriting

Working with mod-rewrite URLs such as "mysite.com/state/NY" or "mysite.com/state/NY/Bronx" would be parsed as urls like this : http://mysite.com/state.php?state=NY&region=Bronx

This allows you to use a single PHP file that is being redirected to from different URLs by mod-rewrite, and hence dealing with all the data-fetching and processing on a single PHP file.

This is done using .htaccess usually, you can read more about using .htaccess and mod-rewrite on google or this link: http://corz.org/serv/tricks/htaccess2.php

Good luck!
Shai.


You want to use something like mod_rewrite to rewrite the incoming URL from http://example.com/foo/bar to something like http://example.com/script.php?var1=foo&var2=bar. From there you can write the script to pull from the database and display output as appropriate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜