By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,159 Members | 1,941 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,159 IT Pros & Developers. It's quick & easy.

Logic Flow in PHP

P: 24
I am currently a real newbe in the world of PHP and webdesign in general. I currently writing my first PHP application. Although unfortunately I did not plan it out.

I need to know what is the best way to design web applications. Just a few tips will do.

Maybe if I show you all an example (not finished) this may help you to understand what I mean a little better.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <? 
  3. require_once('../config/Dbconnector.php');
  4. $connect = new Dbconnector(); 
  5.  
  6. $local = $_SERVER["PHP_SELF"];      
  7.  
  8. if (!$_GET)
  9. {
  10.     header("Location: index.php");
  11. }
  12.  
>>> Here is what I mean in program flow
Here at the beginning of the script if it dosent get any variables it goes back to the index page of the website.

Expand|Select|Wrap|Line Numbers
  1.  
  2. else if ( $_GET['mode'] )  
  3.  
>>> otherwise if it gets the variable mode it flows into
the next part
Expand|Select|Wrap|Line Numbers
  1.  
  2. {
  3.  
  4.      if ($_GET['mode'] == "create") //>>>>> if mode =  create do this
  5.     {
  6.          echo "League Name: ".$_POST['name']."<br/>";
  7.          echo "Number of Groups: ".$_POST['num']."<br/>";
  8.          echo "League Type: ".$_POST['type']."<br/>";
  9.  
  10.          if (isset($_POST['num']))
  11.          {
  12.                 //some more code
  13.                 exit();
  14.                       }
  15.  
  16.                     include("include/create.php");  // OTHER WISE include this into page
  17.         exit();
  18.     }
  19.  
  20. }
  21.  
  22.  
  23.  
  24. else
  25. {
  26.     echo "SORRY INCORRECT SANTAX";
  27. }
  28. ?>
  29.  
See in my theory in all major web applications all form elements are sent via POST and if you wanted to access some particular page with in the application you use on a link i.e
Expand|Select|Wrap|Line Numbers
  1. <a href = "page.php?id =<? echo $variable ?>"> click here </a>
.

Sorry I might have over complicated this question. I don't really know enough about the application flow to know what I am asking truely.

If you can decipher this message I would really appreciate it.

Thank you.
Jul 25 '07 #1
Share this Question
Share on Google+
6 Replies


ilearneditonline
Expert 100+
P: 130
Unless I am way off, how are you going to POST and GET from the same page at the same time? If you click a link, generally you will use $_GET for that. Of course you could have it run some javascript and POST a form, but not sure that you would want to do that except with the exception of using AJAX to POST to a server side script.


So, what is your question really? I didn't see any questions, just some statements.
Jul 25 '07 #2

P: 24
Ok here is my question. When designing a web application. What is the best way about it?

Also I wondering how do you experts think out the program flow.

I triend to give you an example earlier on how I think it would be done. Like if no $_GET variables are sent then redirect the location.
If that works then go on to another element of the application.

Hope you can understand what I am on about.

Thnak you.
Jul 25 '07 #3

ilearneditonline
Expert 100+
P: 130
Ok here is my question. When designing a web application. What is the best way about it?

Also I wondering how do you experts think out the program flow.

I triend to give you an example earlier on how I think it would be done. Like if no $_GET variables are sent then redirect the location.
If that works then go on to another element of the application.

Hope you can understand what I am on about.

Thnak you.
I would not consider myself an expert, but since you are asking. I would probably do it very similar to what you showed. Unless it is dealing with authentication, i would set some varibles to empty strings or something and display that.
Expand|Select|Wrap|Line Numbers
  1.  
  2. if(! $_GET)
  3. // do something. If it is only 1 action, you don't need to use the brackets.
  4.  
Jul 25 '07 #4

kovik
Expert 100+
P: 1,044
Unless I am way off, how are you going to POST and GET from the same page at the same time? If you click a link, generally you will use $_GET for that. Of course you could have it run some javascript and POST a form, but not sure that you would want to do that except with the exception of using AJAX to POST to a server side script.


So, what is your question really? I didn't see any questions, just some statements.
You are way off. Very. Make a post here and look at the URL. Do you see any GET variables in the query string? Then press submit. Do you think that data was sent through the POST method, or also stuck onto the query string? They can coexists at any time.
Jul 26 '07 #5

kovik
Expert 100+
P: 1,044
You guys have some flaws. if(!$_GET) is a generally senseless call, as the logical equivalent to what you are trying to accomplish is:

Expand|Select|Wrap|Line Numbers
  1. if(empty($_GET))
Also, when you check for $_GET['mode'], you would receive a notice if $_GET['mode'] was never set, as the index would never have existed in the array. What you want is this:

Expand|Select|Wrap|Line Numbers
  1. if(isset($_GET['mode']))
Jul 26 '07 #6

kovik
Expert 100+
P: 1,044
On the issue of program flow, what you want is a separation of duties and a logical flow. You are still programming procedurally, so your separation of duties wouldn't be nearly as organized as object-oriented programming. However, you can still simulate it. What you want to do is have your back-end things stay in the back-end and your front-end things stay in the front-end. It's much more complex than that, but if you keep those basics in mind, you'll do okay.

Separating form from function will greatly increase the neatness of your code, and make it more manageable in the process.
Jul 26 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.