Welcome visitors of MIC Computer

Welcome to my blog. With this blog you can post your question about computer and programming for absolutely free (free consultation sponsored by MIC Computer).. Well what are you waiting for just feel free to post your question or share with me about your computer / programming experience

Monday, March 19, 2012

Include external files for php, javascript, and css

We can include external files for PHP, javascript, and css. Using external files is really good for us because we can save a lot of time coding by using it more and more time.
For example, you have already make a css file to custom your html code for all your web page, then you can just link it to every page on your html file. So if you want to change the color of your web page background, you just need to change only 1 file and it will affected to all your web page. Here is the way to include external file.
For php:
include ("filename.php");
require ("filename.php");
include and require are same but they are different when there is an error occurs.
include will generate warning but it continues the script. require will generate fatal error and stop the script.

For javascript:
<script type="text/javascript" src="filename.js"></script>

For css:
<link rel="stylesheet" type="text/css" href="filename.css" />

Hope this can help you

Friday, October 28, 2011

PHP, Javascript, Java, and other C# style language Operators


Arithmetic Operators
Operator Description Example Result
+ Addition x=4+3 x=7
- Subtraction x=10-3 x=7
* Multiplication x=2*9 x=18
/ Division x=6/2
y=5/2
x=3
y=2.5
% Modulus (division remainder) x=7%2
y=9%3
z=10%4
x=1
y=0
z=2
++ Increment x=8;
x++;
x=9
-- Decrement x=8;
x--;
x=7
Assignment Operators
Operator Example Equivalent
= x=y x=y
+= x+=y x=x+y
-= x-=y x=x-y
*= x*=y x=x*y
/= x/=y x=x/y
.= x.=y x=x.y
%= x%=y x=x%y
Comparison Operators
Operator Description Example
== is equal to 2==2 returns true
3==2 returns false
!= is not equal 2!=2 returns false
3!=2 returns true
<>
is not equal (only at PHP) 2<>2 returns false
3<>2 returns true
> is greater than 2>3 returns false
3>2 returns true
< is less than 2<3 returns true
3<2 returns false
>= is greater than or equal to 2>=2 returns true
2>=3 returns false
3>=2 returns true
<= is less than or equal to 2<=2 returns true
2<=3 returns true
3<=2 returns false
Logical Operators
Operator Description Example
&& and x=2
y=3 (x < 5 && y > 2) returns true
|| or x=2
y=3 (x < 1 && y > 2) returns true
! not x=2
y=3 !(x==y) returns true

Wednesday, October 26, 2011

Javascript Procedure and Function

As an programming language that support OOP, Javascript also have procedure and function. Procedure and function on javascript has the same format like PHP and any other C++ style language.

function procedure_and_function_name(var1,var2,...,varX)
{
javascript code
}

As you can see procedure and function format has the same format. The different is function has a statement like this:

Return(variable_or_value);
 here is some example:
Example of procedure:
function message(message_contain)
{
alert("This is my message "+message_contain);
}

Example of function:
function message(message_contain)
{
return("This is my message "+message);
}
echo(message("Hello friend"));

Hope this can help you

Monday, October 10, 2011

PHP Procedure and Function I

Every object oriented programming (OOP) should need a procedure and function. PHP is also OOP so it also need procedure and function. To declare a procedure or function, we have a same format

function hello(message)
{
echo(message);
}
the above example is a PHP procedure. Althougt you see that the declaration is function :). This is the example of PHP function.
function hello(message)
{
return("my message is " . message);
}
this is a PHP function, can you see the different? Yes you are right. The different is there is return statement as a return value on PHP function. That's all..

Thursday, September 29, 2011

PHP, Javascript, CSS block scripting

How can server, browser or we can recognise what kind of script at an HTML document? We use some block scripting to open and end it up.
For PHP we use

<?php
php script goes here
?>
we can also use this:
<?
php script goes here
?>
but I always use <?php and ?>

For Javascript we use
<script type="text/javascript">
Javascript script goes here
</script>
we can also use this
<script>
Javascript script goes here
</script>

For CSS we use
<style type="text/css">
CSS style goes here
</style>

Some really basic C# style language (PHP,JavaScript,Java, etc)

Here is some basic rule for some C or C# style language like PHP, Java, Javascript, etc.

  1. always use semicolon ";" at the end of each command line
  2. usually case sensitive
  3. use bracket for block command like this
    if (some condition)
    {
    } else {
    }
  4. can use quote ' or double quote " for string variable like this "my string" or 'my string'

PHP Variable

PHP also have a variable to store temporary data. Just like Javascript variable, PHP variable can store anykind of data in 1 variable. For example, you can store 234 (number) in a variable and then change it to "Hello" (string) later.
PHP have some rule if you want to declare a variable:

  1. a name must start with letter or underscore "_"
  2. a variable name must contain only alpha-numeric characters or underscore (a-z, A-Z, 0-9, _ )
  3. we cannot use space for variable name but we can use _ or with capitalization ($my_var or $myVar) 
  4. php variable is case sensitive