Monthly Archives: July 2010
Displaying Content of a Text File in PHP
<?php $file=’info.txt’; $fobj=fopen($file,"r"); $text=fread($fobj, filesize($file)); echo("<h2><font color=’blue’>Displaying Content of a Text File</font><h2>"); echo("<br>"); echo("<font size=3>"); echo($text); echo("</font>"); fclose($fobj); ?>
Creating Constructors with Classes in PHP
<?php class student { var $name; var $age; var $grade; function student($n,$a,$g) { $this->name=$n; $this->age=$a; $this->grade=$g; } function display_info() { echo("<p>Name : $this->name"); echo("<p>Age : $this->age"); echo("<p>Grade : $this->grade"); } } $sobj = new student("Item Raja","15","A"); echo("<center><h2>Displaying Student Information</h2></center>"); echo("<font … Continue reading
Example process of creating classes and objects in PHP
<?php class emp { var $name; var $address; var $dept; function assign_info($n,$a,$d) { $this->name=$n; $this->state=$a; $this->dept=$d; } function display_info() { echo("<p>Employee Name : $this->name"); echo("<p>State : $this->state"); echo("<p>Department : $this->dept"); } } $empobj = new emp; $empobj->assign_info("kaka lname","California","Accounts"); echo("<center><h2>Displaying Employee … Continue reading
Using Custom Error Handler in PHP
<?php error_reporting(E_ALL); function ErrHandler($errorno, $errorstr, $errorfile, $errorline) { $display = true; $notify = false; $halt_script = false; $error_msg = "<br>The $errorno error is occurring at $errorline in $errorfile<br>"; switch($errorno) { case E_USER_NOTICE: case E_NOTICE: $halt_script = false; $notify = true; … Continue reading
Generating Errors Using the trigger_error() Function in PHP
The assert() function checks whether the divisor is zero or not. The error_log() function sends the message, Cannot perform division by zero, to the log file specified by the second parameter when the divisor is zero. <?php // set the … Continue reading
Using Nested Functions in PHP
<?php function msg() { echo("<center><h2>Displaying even numbers</h2></center><p><p>"); function displayeven() { $ctr=0; echo("<font size=4>"); for($i=2;$i<=100;$i+=2) { echo("$i "); $ctr++; if($ctr%10==0) { echo("<p>"); } } echo("</font>"); } } msg(); displayeven(); ?>
Example of User-Defined Function in PHP
<?php echo("<center><h2>Displaying even numbers</h2></center><p><p>"); function displayeven() { $ctr=0; echo("<font size=4>"); for($i=2;$i<=100;$i+=2) { echo("$i "); $ctr++; if($ctr%10==0) { echo("<p>"); } } echo("</font>"); } echo("<center><h2>Displaying even numbers</h2></center><p><p>"); displayeven(); ?>
Using the for Loop in PHP
<?php echo("Prime Numbers between 1 and 30<p>"); //For loop from 1 to 30 for($var=1;$var<30;$var++) { $ctr=0; for($k=2;$k<=$var/2;$k++) { $d=$var%$k; if ($d == 0) { $ctr=1; break; } } if($ctr==0) { echo($var); echo("<br>"); } } ?>
Using the while Loop in PHP
<?php $a=2; echo("<p>Even Numbers from 2 to 30<p>"); while ($a <=30) { echo("$a <br>"); $a=$a+2; } ?>
Using the switch case Conditional Statement in PHP
<?php //Initializing variables $a = 10; $b = 5; echo("1. Addition <br>"); echo("2. Subtraction <br>"); echo("3. Multiplication <br>"); echo("4. Division <br>"); $ch=3; switch ($ch) { case 1: $d=$a+$b; echo("The sum of the two numbers is $d"); break; case 2: $d=$a-$b; … Continue reading
Find maximum of three numbers using IF ELSE in PHP
<?php $x=10; $y=20; $z=30; if($x > $y) { if($x > $z) { echo("The maximum number is "); echo("$x<p>"); } else { echo("The maximum number is "); echo("$z<p>"); } } else { if($y > $z) { echo("The maximum number is "); … Continue reading
Example of IN and NOT IN SQL Queries
SELECT id FROM stats WHERE position IN (’Manager’, ‘Staff’) SELECT ownerid, ‘is in both orders & antiques’ FROM orders, antiques WHERE ownerid = buyerid UNION SELECT buyerid, ‘is in antiques only’ FROM antiques WHERE buyerid NOT IN (SELECT ownerid FROM … Continue reading
what are DDL, DML and DQL?
DDL (Data Definition Language) refers to the CREATE, ALTER and DROP TABLE statements DML (Data Manipulation Language) refers to the INSERT, UPDATE and DELETE statements DQL (Data Query Language) refers to the SELECT statements DCL (Data Control Language) refers to … Continue reading
How to fix SQL Network Interfaces, error: 26
You may get the following error when you have developed an application, and then you move your site to another server (like your web host’s server): An error has occurred while establishing a connection to the server. When connecting to … Continue reading
What is a mnemonic?
What is a mnemonic? It is very difficult to understand a program if it is written in either binary or hex code. Thus the manufacturers have devised a symbolic code for each instruction, called a mnemonic.
What are the different jobs that the CPU is expected to do at any given point of time?
What are the different jobs that the CPU is expected to do at any given point of time? The CPU may perform a memory read or write operation, an I/O read or write operation or an internal activity.
How does the microprocessor communicate with the memory and input/output devices?
How does the microprocessor communicate with the memory and input/output devices? The microprocessor communicates with the memory and the Input/Output devices via the three buses, viz., data bus, address bus and control bus.
What are the three main units of a digital computer?
What are the three main units of a digital computer? The three main units of a digital computer are: the central processing unit (CPU), the memory unit and the input/output devices.
What is the technology used in microprocessors?
What is the technology used in microprocessors? NMOS technology is used in microprocessors.
What is a microprocessor?
What is a microprocessor? A microprocessor may be thought of as a silicon chip around which a microcomputer is built.