Jump to content
xisto Community
Tran-Gate

Website Structure PHP, MySQL, HTML, etc.

Recommended Posts

Hey guys, I am a very, VERY, curious person on finding out how things work on the computer if I find them interesting and I can't stop thinking about the thing until I find the answer. The sooner I find the answer, the less time I get a headache. So I was wondering how websites work. I mean how everything would be put together. Like how a game would be put together linking object files and libraries(i think). How would you export a website template onto an actual webpage and how would you edit an HTML file to make it fit the template exactly. How would you know how tall(length) your website template would be? How does PHP work with HTML and how could you put together MySQL and PHP together. I think that MySQL is a database manager, right? But how would you access the database/website from your computer? And how does PHP work with MySQL? So many questions. I am sorry for asking so many questions. I would at least appreciate if you(the reader) would at least answer the questions you DO know so I could learn something and stop wondering so frequently. Another favor I want to ask you is to try to make your posts/replies descriptive so I could possibly picture it. =) Thank you in advance~!!

Share this post


Link to post
Share on other sites

Hello, tran_gate, welcome to the Xisto.Good questions, and I am certain that you will be getting lots of replies to the questions you ask. I will offer this reply to kick off the flurry.HTML is the language of choice for most web-sites. The name says it all... Hyper Text Markup Language. The purpose of HTML is to provide information available via the internet in a 'structured' fashion. By structured, I mean that the page should have a Title (heading), Divisions of the page (sub-headings), paragraphs, lists, and so forth. HTML provides the means to 'structure' the content of a page.CSS (Cascading Style Sheets) offer a means to 'style' the page. All the headings can be modified, sized, coloured, etc and font-styles added using CSS. The styling can be held in a linked, external page, in the head of a page, or 'in-line' with the element it is styling.Many pages on the web are 'static' pages, meaning that the content of the page is written once and rarely changed, except by the page Author and then re-uploaded to the Hosting Account.Dynamic pages, on the other hand, often use a server-side scripting language like PHP or ASP to modify the site content based on user-made choices. If you see an URL containing a 'query string such as ?id=1&member=ralph, php will use that information to do something. What it does depends on the particular script and the actual values contained n the query string. Example: '?act=admin' might mean to produce the Admin Panel of a site. PHP is used to provide the HTML content of a site based on the query string and often is used to read/write information from a Database. Again, the 'query string' is used as a 'seed' to select the DB contents, and then writes the html content onto the page, which is then styled using CSS.Is that what you needed to know?

Share this post


Link to post
Share on other sites

Hmmm......You asked for an entire web development course in a single question :)

 

I don't know much about templates. But I will tell you something about HTML, PHP and MySql.

 

First,

How does HTML work with PHP.

Actually HTML doesn't work directly with PHP. PHP is a server side scripting language, like javascript which is for client side. A scripting language actually does something in response to an event(s). Since PHP is server side language, first we need a Web Server, to process the PHP code and PHP language and its libraries. We embed the PHP code into HTML page with

<?php and ?> tags. The code will be on the server side. The client cannot see that. When a user requested a page with PHP, the server executes the PHP code, and will show the result in HTML page. That is the html part in the PHP page

will be displayed.

 

To make it simple, I will give you an example.

 

For example, you want to develop login page into some xyz.com site. So, the login page has two fields...username and password and a button to submit them. Let the page be login.html. The fileds username, password and submit are a part of a form in the login.html page. The form generates the event(I already told you, scripting language needs an event to start) when you click submit button. The form has an option(action what to do). When you click the submit button it executes the action.

Since you want to login, let the action be processlogin.php. That means, when you click the submit button, the processlogin.php page will be initiated at the served and the username and password will be sent to it.

 

(Sending information to server invloves two methods GET and POST. They are somewhat technical. So I will explain them simply. When you click the button, if you can see the username and password in your browsers address bar it

is GET request. If they don't appear at address bar it is POST request.)

 

First let us assume our login.html page will do the following things.

1. It displays the fields username, password and submit button.

2. If the userclicks the submit button, it sends the username and password to processlogin.php page.

 

So, let us come to the server side. Assume our processlogin.php page will do the following things.

1. First it receives the username and password.

2. It connects to the database. (MySql, for example)

3. It verifies the username and password pair.

4. If the pair matches it gives you welcome message. Or if it fails, it will tell you invalid username or password.

5. Disconnect from database.

 

How PHP connects to the database? PHP has some methods to connect to database, for example mysql_connect. Using this method mysql connects to some database we specify.

 

After that PHP executes some query at database(using mysql_query method. For example, assume this query

select * from logindetails where name='username'). Let us call it result.

 

Next our PHP code compares the username and password with the result. As per the result, it executes the 4th step. That is

it displays the HTML part of our processlogin.php page. And it will disconnect from database. simple....

 

I tried my best to make it simple and general rather than technical. If you know something about database and HTML you'll understand it easily. If you can't understand anything or something, ask me and I am glad to expalin it in detail.

Edited by xpress (see edit history)

Share this post


Link to post
Share on other sites

Aha! A question i could write a whole book on! But xpress got most of it down already! Let me talk about HTML and templates, HTML has already been described and it was the first language i ever learned, followed closely by javascript, then PHP, MYSQL syntax, CSS a little of VB and ive stopped there! IF you wanted to make a templste you would usually use a recognized format, for example you would draw it up in a graphics program first to create the graphics, perhaps having a section to the left containing a list of links, a large header image at the top and the content in the remaining space. To make the template fit the screen you have two options. The first is to use flexibly sizing. Within HTML you size objects with code like : Width=40% height= 100% so if i was sizing an image it would take up 100% of the browser's vertical space and only 40% of its horizontal space, so the image would be stretched from top to bottom, no matter what size window you had. If you have a screen which is 800px by 600px it would fill that space, or if you had a screen the size of a cinema screen it would still fill up all the vertical space. so you can see that if i was sizing a template i could use percentages to make sure a top image only took up 10% of the space leaving 90% for the webpage content. Or you can use static sizing using pixel values like: height=100px width=800px (you dont need to add "px" to the end but i usually do) So in this example the image would be 100px wide which is a VERY optimal size for a header image or any other part of a website as 800x600 is the second most common screen size so you would not loose out visitors. So if i were to create a template using pixel values i would make sure that all my content fits within 800px wide. That way 99% of computer users can see ALL of my website! Good times! As i said the first step in making a template is to draw it out on paper or a computer. You then create the individual elements. So you would draw the entire template and then cut and paste the little buttons and other graphics and save them individually. If you dont already know HTML try learning it, its pretty easy stuff! As for how do i know how tall to make the template, i dont need to. If i make a table that is 20 pixels high and i put in 100 lines of text that use up 400px of space the table will automatically get bigger to fit the text in (unless i tell it not to but why would i do that?!) So no matter what happens the HTML template will ALWAYS be tall enough for the content inside it. Also when you specify a background colour or something that will fill the whole page of the background. eg bgcolor=black would make the background black, no matter how long my page was, whether it was one page long or a million pages long, the background is always black, so theres no worries about the page turning plain white half way down!As touched on by xpress the interaction between PHP and a MYSQL database is fairly simple. There are a few steps:1) Connect to the database: $link = mysql_connect("Server", "username", "password"); 2) Select the database: mysql_select_db("database_name", $link); NOTE: "$link" is a variable as shown by the dollar sign. When doing the first step you must assign a variable to that function. Basically the first step creates a link to the database and that link is stored within the $link (or whatever you want to name it) variable. Its like a telephone call and the $link variable keeps the call open. Within this there is no connection!3) execute a query: (using xpress' example:) $result = mysql_query("SELECT * FROM table_name WHERE field='VALUE'", $link); NOTE: See the $link variable? It tells the code what connection to use. Also note ive added a WHERE clause, so if i put in a username where VALUE is it would look through the database and return any and all rows with the username i tell it to find. Useful!4) Get the data from the $result variable: We use a variable called an array. An array can store lots of info for example: $array[0] = "ZERO"; $array[1] = "ONE";That single variable can contain two (or a million!) different sets of data. So in my example of the query it might return 3 rows so we use: $row = mysql_fetch_array($result); So now the variable $row contains ALL of the data returned from the database ready for me to look through it, check it, show it to the user etc.....And they are the basic steps involved in using a MYSQL database with PHP. As i understand it (im not sure on this, even after about 2-3 years of personal experience!) MYSQL is simply a database format. In fact Microsoft Access has support for mysql code/queries. PhpMyAdmin is a tool used for managing these databases. (so you can imagine PhpMyAdmin is like Microsoft Access. It isnt a database in itself it is more like a program or tool used to make the database look friendly and easy to edit! I hope that helps :) PHP is an amazing language! So much can be done with it. In fact what language powers this forum? PHP! alongside CSS (for formatting) Javascript (the shoutbox (technically AJAX but basically Javascript!) and for the quick reply) MYSQL (to get the data our of the database, this data includes user login info and post data etc..) HTML of course to build the actual page. and i think thats it! SO if you were good enough you could make your own forum, shopping cart, login systems, contact forms, newsletter mailing lists, text based games (like those text based RPGs) Profile sites and sites like myspace etc... loads of stuff!To make graphical games you would need to learn a language like Java or flash which do indeed use libraries and object/class files. But i never got on with those!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.