using an 'if' statement in PHP
5 posts
Page 1 of 1
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
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
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
2) Using an else statement in PHP
//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,
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
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;
}
?>
_Crazy wrote:This is my 'version'/'way of doing it' of php 'if' statements.why should a number be in quotes ?
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; } ?>
$Variable1 = 1;
else its a string
btw, did you watch the last post date ? 20/06/10
thats almost 6 months ago
Also, why would you use whitespaces in an if statement, that just makes a file bigger and a bit easier to read...

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;
?>
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!
5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023