473,471 Members | 2,040 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Logic Flow in PHP

24 New Member
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
6 2150
ilearneditonline
130 Recognized Expert New Member
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
traineeirishprogrammer
24 New Member
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
130 Recognized Expert New Member
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
1,044 Recognized Expert Top Contributor
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
1,044 Recognized Expert Top Contributor
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
1,044 Recognized Expert Top Contributor
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

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

Similar topics

2
by: Xenophobe | last post by:
I'm having a brain freeze on how to go about creating the logic for evenly distributing a group of items in rotation through multiple iterations. I'm particularly looking for logic flow help and...
2
by: Steve Jorgensen | last post by:
Hi all, In the code I'm working on to learn Java, I wanted to check to see if a string can be converted to a BigDecimal, and get the BigDecimal value if so. There is no assumption that the...
2
by: Thiko | last post by:
I have a sql server automatic job set up containing 2 steps. First step is an Operating System Command (CmdExec) type job which runs a .bat file which copies across a backup file to this machine....
11
by: Robert Bowen | last post by:
Hello all. I have been given mock-ups (in static HTML) of some pages for a site I am working on. The client would like these pages to look exactly as they do now. The problem is that the content is...
8
by: - | last post by:
Hi to All, To reproduce: The expression: object result = flag ? (long) 0 : (double) 0; always evaluated as a double... see dissassembly to ensure the bad compiled code.
11
by: hazz | last post by:
before I start filling up the first page of perhaps many pages of code with if/then or switch:case buckets, I wanted to step back and see if there is a better way... I will have a table with up to...
0
by: Sam | last post by:
I am fairly new to ASP. Net 2.0, background MS Access 2000/2003 and working knowledge of SQL 2000. Scenario: Page1: Blank Page loads with 2 Text Boxes (TxtLast, TxtFirst), a Command...
10
by: Frank van Wensveen | last post by:
Friend, coders, fellow wage slaves, lend my your ears. I believe that in a perfect world the design of a website (or feature on a website) should be totally separated from its design and the data...
5
by: salberts | last post by:
Hi, I am writing an application that has its UI and Logic layers. My initial idea was to launch the two layers on two different threads and manage calls made by the UI to the Logic manually....
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.