using an 'if' statement in PHP

5 posts Page 1 of 1
Contributors
User avatar
rocky4126
VIP - Donator
VIP - Donator
Posts: 258
Joined: Mon Nov 16, 2009 7:39 pm

using an 'if' statement in PHP
rocky4126
1) The basic command:

Ok so most people wonder how to show stuff like game achievements, check user permissions etc etc and since I am working on one of these projects I will tell you but you must promise me one thing. USE CnS FOREVER! lol. Anyway here we go
Code: Select all
//This is the simple bit
<?php if (//something here. Remember variables use $ so for example:
//$user_class->admin == 1) { //either end the php statement and add something between or just continue. Search up on what you should do to make it work out.
} ?>//end PHP block
//Some random stuff here, tables, 
2) Using an else statement in PHP
Code: Select all
//This is the simple bit
<?php if (//something here. Remember variables use $ so for example: //$user_class->admin == 1) { //either end the php statement and add something between or just continue. Search up on what you should do to make it work out.
 } else { //This time we add the if statement to do something if admin does NOT equal 1.
//either end the php statement and add something between or just continue. Search up on what you should do to make it work out.
} ?> //end PHP Block
--------------------------------
A little disclaimer.
I Have all the rights to remove this post and/or it's contents. This code follows the site found at http://www.frozenmafia.co.cc. If you have a problem then please do not hesitate to email me or PM me. I may also request rude comments to be removed by either codenstuff or another member of the team. If you do not have any problems then please continue with no worries.

Note to you all:
If I recieve 5 abusive comments on this topic I will request it to be locked and will not request an unlock.

Thanks, John
User avatar
_Crazy
Just Registered
Just Registered
Posts: 5
Joined: Thu Nov 25, 2010 11:47 pm

Re: using an 'if' statement in PHP
_Crazy
This is my 'version'/'way of doing it' of php 'if' statements.
Code: Select all
<?php
$Variable1 = "1";
if($Variable == "1") {
echo "Variable = 1";
sleep(rand(2,3));
die;
}
else {
echo "Variable does not equal x";
sleep(rand(2,3));
die;
}
?>
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

Re: using an 'if' statement in PHP
Axel
_Crazy wrote:
This is my 'version'/'way of doing it' of php 'if' statements.
Code: Select all
<?php
$Variable1 = "1";
if($Variable == "1") {
echo "Variable = 1";
sleep(rand(2,3));
die;
}
else {
echo "Variable does not equal x";
sleep(rand(2,3));
die;
}
?>
why should a number be in quotes ?

$Variable1 = 1;
else its a string

btw, did you watch the last post date ? 20/06/10
thats almost 6 months ago
http://vagex.com/?ref=25000
User avatar
rocky4126
VIP - Donator
VIP - Donator
Posts: 258
Joined: Mon Nov 16, 2009 7:39 pm

Also, why would you use whitespaces in an if statement, that just makes a file bigger and a bit easier to read...
Image
User avatar
Scottie1972
Codenstuff Elite
Codenstuff Elite
Posts: 953
Joined: Thu Jan 14, 2010 5:48 am

Here is another way of using multi $var for the same result.

Example 1 very simple without error checking
<?php
$user_class = $_SESSION[' USER_CLASS ']; or "1";
switch($user_class)
{
case 1: //Basic User
//Hidden Menu Link
$user_class_editor = 0;
break;

case 2: //Member
//Show Menu Link
$user_class_editor = 1;
break;

case 3: //Admin Control
//Admin Option
$user_class_editor = 2;
break;
}
?>


OK so Example 2 will have an error checking in case something goes wild.
<?php
$user_class = $_SESSION['USER_CLASS']; or 1;
switch ($user_class):
/////////////////////
case '1'://Basic User
//Hidden Menu Link
$user_class_editor = 0;
break;
/////////////////////
case '2': //Member
//Show Menu Link
$user_class_editor = 0;
break;
/////////////////////
case '3'://Admin
//Admin Control
$user_class_editor = 0;
break;
/////////////////////
default:
echo "There was an Error some where.";
endswitch;
?>
This post was created using Feather Editor Unlimited!
Image
5 posts Page 1 of 1
Return to “Help & Support”