![]() |
Some one please explain me this part of code
I have completed PHP course , i know basics well .Im doing a case study on project to develop my PHP knowledge , if you have time, please explain me $GET[a],
1.why "a" is needed. 2.From where value is passed to "a"? the above $GET[a] is repeated in many php pages on this project, i couldnt figure out , why? if you need complete code,i could send you Below is the some code of index page. Index page consist of book search and login section. <?php session_start(); include 'conn.php'; ConnectDB(); $errMsg = ""; if ($_GET[a]=='2') { //$a="search.php?txtsearch=" . $_POST[txtsearch]; $a="search.php?cboCategory=" . $_POST[cboCategory]; $_SESSION[searchtext] = $_POST[txtsearch]; $_SESSION[searchauthor] = $_POST[txtauthor]; $_SESSION[searchbook] = $_POST[txtbook]; $_SESSION[cboCategory] = $_POST[cboCategory]; header("Location: $a"); } if ($_GET[a]=='1') { $sql="select nUserId,cUserType from Users where |
First off, welcome to the community :-) !
There are actually two types of these predominantly used to pass variables to various documents. You've probably seen them when browsing websites. Typically, but certainly not always, they consist of key/value pairs. Example: Code:
http://www.example.com/index.php?var1=I Love&var2=TalkPHPWhat I mean by key/value pairs is that the first item is the key, and the second being its value. Take a look at the following as shown in our example: Code:
var2=TalkPHPvar2 would be the key, and TalkPHP is the value for that key.Now that we know that, to answer your question. Using our example again we would extract the value TalkPHP from the URL using $_GET['var2'];. If you're currently knowledgeable about arrays, then $_GET is simply one big array that contains all the variables passed to it via GET (Not POST, for POST we have $_POST).In your example, the GET variable a can be set to 1 or 2, or not at all. That is why there is an if statement checking its value.To tie this up, using our above example of: Code:
http://www.example.com/index.php?var1=I Love&var2=TalkPHPvar1 and var2):php Code:
I hope I have explained it well for you :-) Please let me know if not. |
Thank you , Wild honey for quick reply with informative examples . i think i confused you with my bad english sorry , my question was why does we use $GET[a] in the index page . Why that value is checked before using Login or Searching book.
|
They're performing different actions based on what the
a variable contains. I wouldn't recommend doing that though. Really you should have different pages for different actions. |
| All times are GMT. The time now is 06:47 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0