vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   Basics Of PHP [Part 2] (https://vborg.vbsupport.ru/showthread.php?t=59914)

zahco 06-11-2004 09:38 AM

thanks a lot MindTrix
i have worked with (( if )) Statement codes om my computer server and all of them working good

best regards
zahco
http://www.arabswell.com/vb/

xTerMn8R 08-08-2004 03:01 PM

Hey it looks a lot like general if then else statements in HTML, is the if in PHP the same as HTML?

I think the time you take to type these tutorials is a real example of true dedication to coding and sharing open code. I commend you on ur efforts and also hope these types of post will continue, as they certainly help us cut and pasters get a better feel for coding our own ...

How bout a tutorial about how to do a eval on voting on a poll. ie. Users cant login to Site till ya vote on a certain poll...

Great work and thank you for you time ...

Guy G 12-12-2004 04:15 PM

will there be a part 3? a complex one? arrays and other stuff?

Michael Morris 12-14-2004 10:28 PM

Few things to keep in mind about if statements. First, and most important, is that they are the fundemental building block of all programming languages. PHP follows the formatting conventions of C++

Second, if clauses are supported in the XML templates, though their format is different

HTML Code:

<if condition=" "> Do This </if>
And Visual Basic and Javascript use yet a third format

Code:

IF condition THEN
    action
END IF

Master the principles of one and you should be able to apply it to the others with a little adjustment.

In the case of PHP the actions outlined between the {} brackets is carried out only if the statement evaluates to true. If it evaluates to false then the information is ignored.

PHP allows you to simply check if a variable is set. For instance

PHP Code:

if ($bbuserinfo)
{
echo 
'The variable $bbuserinfo has a value or is set as an array.'


If $bbuser info isn't set or hasn't been declared as an array at all this returns false.

You can set a variable specifically to true or false. Such a variable is known as a Boolean variable. If a variable isn't boolean and you check it then it returns true for all values but Null and 0, which return false.

Mindtrix went over == adequately, but you also can check for greater than (>), less than (<), greater than or equal to (>=), lesser than or equal to (<=). All of these are only useful if the compared variables are numeric - I'm don't know how they'll behave if strings are compared.

Examples

PHP Code:

if ($x $y)
{
echo 
'X is greater than Y';
}

if (
$x $y)
{
echo 
'X is less than Y';
}

if (
$x <= $y)
{
echo 
'X is less than or equal to Y'


Logical Operands

In in addition to the comparison operands, you will see frequent use of logical operands: NOT, AND, OR, and XOR. These allow you to test multiple conditions. For instance

PHP Code:

if ($x $y AND $a $b)
{
echo 
'$x is equal to $y and $a is equal to $b';


The and operand requires both sub-statements to evaluate "true" for the overall statement to evalutate true.

AND is often shorthanded as &&

OR evaluates true if either or BOTH the conditions are true.

PHP Code:

if ($x OR $y)
{
  echo 
'true';


If either X or Y is true, then the statement is true as a whole. If both are true the statement still holds. Only when both are false does the statement evaluate false.

OR is often shorthanded as ||

NOT reverses the value of the statement. For instance

PHP Code:

if (!$x == $y)
{
echo 
'X is not equal to Y';


Note this particular example is the same as the mathmetical operand != (not equal).

Not is always shorthanded "!" in PHP. In visual basic and Javascript you have to write it out.

XOR is shor for "Exclusive Or" It excludes the And result. It is logically equivalent to this.

PHP Code:

if (($x OR $y) AND !($x AND $y)) 

XOR evaluates as true if $x or $y is true, but evaluates false if $x AND $y are true. Of course, both XOR and Or evaluate false if both inputs are false.

The final example shows exactly how convoluted if statements can get. Sub-statements can be placed in parenthesis to set them apart.

Functions and If

If a function returns true or false then it can be used in an if statement. For example, the empty function checks to see if a variable is empty (or null). You can use it for a conditional.

PHP Code:

if (empty($x))
{
echo 
"X is empty";


One frequently used predefined function in vbulletin is is_member_of.

PHP Code:

is_member_of($X$Y

If the usergroup # in $Y is among the usergroups stored in $X, it returns true. It's a little easier to see in practice...

PHP Code:

if (is_member_of($bbuserinfo6))
{
echo 
"This is an admin";


The admin group is predefined in vbulletin and group #6. $bbuserinfo is the current user's information. $post is another variable that carries user information while posts are assembled.

Hope this flood of tidbits help.

paulomt1 12-19-2005 10:32 PM

Please, I need help with this:

This line of code is correct?
if (!defined (TABLE_PRX))
or must be:
if (!(defined (TABLE_PRX)))

Thank you

akanevsky 12-19-2005 11:26 PM

Quote:

Originally Posted by paulomt1
Please, I need help with this:

This line of code is correct?
if (!defined (TABLE_PRX))
or must be:
if (!(defined (TABLE_PRX)))


Thank you

Neither of these are correct. Use:
if (!defined('TABLE_PRX'))

paulomt1 12-25-2005 10:25 PM

Thank you for your help :-)

akanevsky 12-26-2005 01:17 AM

You are welcome.

evofile 04-20-2006 05:50 PM

thanks man the guide is very usefull
thank you

zooki 06-02-2006 05:20 PM

interesting thank you ;)


All times are GMT. The time now is 05:19 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01142 seconds
  • Memory Usage 1,761KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_html_printable
  • (9)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete