View Full Version : Trying to understand PHP & MySQL
Loren
08-17-2006, 08:24 AM
I have a potential client that wants me to build a website for him, and has given me a site to go by..now this site is php built, and although i can gleen all want for the javascript i am not clued up on php very well, although definately learnt a lot here thanks to everyone :) and was wondering even though not related to esyn directory would you guys help me to learn a wee bit more, and understand what this all means..
In this index page url of this website it has this:
http://www.amhomesbooks.com/index.php?mode=home <---is this relating to a php file or a MySql table?
There are quite a few links like this
<li><a href="/index.php?mode=text§ion_id=111" class="menuindent">Biography</a></li>
<li><a href="/index.php?mode=contact§ion_id=147"
<li><a href="/index.php?mode=objectlist§ion_id=137"
Are these MySQL arguments? or can these be from a php file?
Vincent Wright
08-17-2006, 09:37 AM
Everyting that goes after ? sign is known as GET-variables. Think of them as parameters that are passed to .php file. Using these parameters in .php file you can contol the output.
E.g.
www.domain.com/index.php?mode=home -- will display Home page
www.domain.com/index.php?mode=faq -- will display FAQ page
Of course you have to program in .php file what to display.
In your .php file these values are accessible via $_GET global variable. In our example above in the first case $_GET['mode'] will contain "home" and in the second case $_GET['mode'] will contain "faq" value.
You can do whatever you want with thiese variables, like this
index.php
<?php
switch ($_GET['mode'])
{
case 'home':
// display Home page here, since "home" was passed in $_GET['mode']
break;
case 'faq':
// display FAQ page here, since "faq" was passed in $_GET['mode']
break;
}
?>
Or like in eSyndiCat....
www.domain.com/index.php?id=123
Here you tell the script to fetch and display category with ID=123. This is convenient since you can handle virtually unlimited number of categories with just one file by passing category id into it.
Hope this helps. If you have more questions feel free to ask.
Loren
08-17-2006, 09:59 AM
Everyting that goes after ? sign is known as GET-variables. Think of them as parameters that are passed to .php file. Using these parameters in .php file you can contol the output.
E.g.
www.domain.com/index.php?mode=home (http://www.domain.com/index.php?mode=home) -- will display Home page
www.domain.com/index.php?mode=faq (http://www.domain.com/index.php?mode=faq) -- will display FAQ page
Of course you have to program in .php file what to display.
In your .php file these values are accessible via $_GET global variable. In our example above in the first case $_GET['mode'] will contain "home" and in the second case $_GET['mode'] will contain "faq" value.
You can do whatever you want with thiese variables, like this
index.php
<?php
switch ($_GET['mode'])
{
case 'home':
// display Home page here, since "home" was passed in $_GET['mode']
break;
case 'faq':
// display FAQ page here, since "faq" was passed in $_GET['mode']
break;
}
?>
Or like in eSyndiCat....
www.domain.com/index.php?id=123 (http://www.domain.com/index.php?id=123)
Here you tell the script to fetch and display category with ID=123. This is convenient since you can handle virtually unlimited number of categories with just one file by passing category id into it.
Hope this helps. If you have more questions feel free to ask.
Thanks Vinny for your help :)
So would i have the above in a separate file? Because i don't see these kind of variables in the index.php or a reference to this file.
I am a little unclear of how you would put or where you would put the variable values?
Do you know of any example scripts that would use this kind of thing? I m the kinda gal who breaks everything down and the rebuilds see..:blink:
Loren
08-17-2006, 10:08 AM
Dave you shouldn't have remove that! You said something about MySQL... Tell me tell me! :air-kiss:
Vincent Wright
08-17-2006, 10:42 AM
Well,
what we talk about are mere URLs that you can type in manually in your static html page or make script generate it in your dynamic php file.
When you see a url like index.php?param1=value1¶m2=value2 it means that when you click on the link you are actually saying to web server serving the pages "Please, run the index.php script for me to generate the output (which my browser will display), but I want you to pass these parameters to the script: param1 assigned value1 and param2 assigned value2". And depending on the parameters passed the behavior of the script will change resulting in different output for each parameter combination.
Vincent Wright
08-17-2006, 10:47 AM
On the other side, you, as developer, can implement certain behavior for each parameter combination: you can just load different files stored on server for different parameter values, you can connect to weather site to fetch temperature values to display on your site, you can collect GPS data and display on your site, or you can even launch a space shuttle :) if NASA gives you priveleges to :))... Or you can simply connect to your MySQL server and fetch specific data.
All I want to say is that as a developer you can program whatever task you want it to complete: be it connecting to some other site, reading and displaying a file, or connecting to mysql database.
Dave Baker
08-17-2006, 11:42 AM
Hello Loren,
My message duplicated message Vincent.
Here: http://www.amhomesbooks.com/index.php?mode=home You have one variable mode with value home. This variable is used for PHP script.
Here: <li><a href="/index.php?mode=text§ion_id=111" class="menuindent">Biography</a></li>
<li><a href="/index.php?mode=contact§ion_id=147"
<li><a href="/index.php?mode=objectlist§ion_id=137"
There are two variables in each case. It is a variable mode with different values in each case and variable section_id. In each case the variable mode is responsible for loading necessary page. In the script this value is checked and transition on that value which in this variable is stored. Variable section_id probably also it can be used in MySQL queries. But I know, this variable is responsible for loading background pages. If the data are stored in database MySQL, this variable specifies the certain cell in which the description background is stored.
Experiment with value of this variable
http://www.amhomesbooks.com/index.php?mode=contact§ion_id=147
http://www.amhomesbooks.com/index.php?mode=contact§ion_id=111 - image from Biography
http://www.amhomesbooks.com/index.php?mode=contact§ion_id=116 - image from Jack
http://www.amhomesbooks.com/index.php?mode=contact§ion_id=122 - image from Things You Should Know
:)
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.