File created:
1)item.php (time spent: 1hr 20 mins)
To view each single item within the database.
2)categories.php (time spent: 1hr 30 mins)
To view all the items, can be sorted according to different categories.
3)mysql_content.sql (time spent: 1/2 hr)
Define the DB schema.
Learnt: To design and use mysql schema and sort the Data by categories.
The while Statement
The while Statement
The while statement is useful, when you want to loop a code until it's conditions are met.Syntax :while (condition)
code ....
Example :");}Output of this code is :
echo "Value is ". $val .". condition not met!
";
$val++;
}
?>
Value is 0. condition not met!
Value is 1. condition not met!
Value is 2. condition not met!
Value is 3. condition not met!
Value is 4. condition not met!
Value is 5. condition not met!
Value is 6. condition not met!
Value is 7. condition not met!
Value is 8. condition not met!
Value is 9. condition not met!
Value is 10. condition met!
Above code loops until the value is 10.
All free PHP video tutorials from start to finish
From this free PHP video tutorial lesson you can watch all essential part of PHP. In this part I orderly organize all free PHP video tutorials. So guys start your PHP journey with us. You can watch all PHP video tutorials from youtube just clicking skip add.
PHP basic free video Tutorials index
Introduction to PHP , Installing XAMPP Part 1 , Installing XAMPP Part 2
Creating Your First PHP File , Writing Your First PHP File , The phpinfo Function
PHP Indentation , PHP echo function , PHP print function , Embedding PHP Inside HTML
PHP comments , Reporting error in PHP , PHP Variables , Concatenation with PHP
PHP if......else Statement , Assignment Operators , PHP Comparison Operators
Arithmetic Operators , Logical Operators , For Loop in PHP , While Loop in PHP
PHP do while Loop , PHP switch Statement , for each Statement
PHP die and exit Functions , PHP Functions basic , Functions with Arguments ,
Functions with a Return Value , PHP Global Variables and Functions
PHP String Functions Part-1 , PHP String Functions Part 2, PHP String Functions Part 3
PHP String Functions Part 4
Introduction to PHP Arrays , Associative Arrays , Multi-dimensional Arrays
PHP String Functions: String Length , String Position Part 1 , String Position Part 2
Replacing Predefined Part of a String , Expression Matching in PHP
Creating Your First PHP File , Writing Your First PHP File , The phpinfo Function
PHP Indentation , PHP echo function , PHP print function , Embedding PHP Inside HTML
PHP comments , Reporting error in PHP , PHP Variables , Concatenation with PHP
PHP if......else Statement , Assignment Operators , PHP Comparison Operators
Arithmetic Operators , Logical Operators , For Loop in PHP , While Loop in PHP
PHP do while Loop , PHP switch Statement , for each Statement
PHP die and exit Functions , PHP Functions basic , Functions with Arguments ,
Functions with a Return Value , PHP Global Variables and Functions
PHP String Functions Part-1 , PHP String Functions Part 2, PHP String Functions Part 3
PHP String Functions Part 4
Introduction to PHP Arrays , Associative Arrays , Multi-dimensional Arrays
PHP String Functions: String Length , String Position Part 1 , String Position Part 2
Replacing Predefined Part of a String , Expression Matching in PHP
PHP advanced free Video Tutorials index
section/tmpl/blog_item.php
here is custom code .. please find
defined('_JEXEC') or die('Restricted access'); ?>
user->authorize('com_content', 'edit', 'content', 'all') || $this->user->authorize('com_content', 'edit', 'content', 'own')) : ?>
item, $this->item->params, $this->access); ?>
item->state == 0) : ?>
item->params->get('show_title') || $this->item->params->get('show_pdf_icon') || $this->item->params->get('show_print_icon') || $this->item->params->get('show_email_icon')) : ?>
item->params->get('link_titles') && $this->item->readmore_link != '') : ?> escape($this->item->title); ?> escape($this->item->title); ?> | item, $this->item->params, $this->access); ?> | item, $this->item->params, $this->access); ?> | item, $this->item->params, $this->access); ?> |
item->params->get('show_intro')) :
echo $this->item->event->afterDisplayTitle;
endif; ?>
item->event->beforeDisplayContent; ?>
item->params->get('show_section') && $this->item->sectionid && isset($this->item->section)) : ?> item->params->get('link_section')) : ?> item->sectionid)).'">'; ?> item->section; ?> item->params->get('link_section')) : ?> '; ?> item->params->get('show_category')) : ?> item->params->get('show_category') && $this->item->catid) : ?> item->params->get('link_category')) : ?> item->catslug, $this->item->sectionid)).'">'; ?> item->category; ?> item->params->get('link_category')) : ?> '; ?> | |
item->created_by_alias ? $this->item->created_by_alias : $this->item->author) ); ?> | |
item->created, JText::_('DATE_FORMAT_LC2')); ?> | |
item->urls; ?> | |
item->toc)) : ?> item->toc; ?> item->text; ?> | |
item->modified, JText::_('DATE_FORMAT_LC2'))); ?> | |
item->readmore_register) : echo JText::_('Register to read more...'); elseif ($readmore = $this->item->params->get('readmore')) : echo $readmore; else : echo JText::sprintf('Read more...'); endif; ?> | |
item->state == 0) : ?>
item->event->afterDisplayContent; ?>
checking if an element is in array or not using in_array() in php
element_in_array.php :
<?php
// Checking if an Element Is in Array or not
$num=array(1,2,3,4,5,6,7,8,9,10);
$element=$_POST['element'];
if (in_array($element, $num)) {
echo 'element found';
}
else
{
echo 'element not found';
}
?>
============================================================
element_in_array_index.php :
<center><b>here checks data is in array or not</b><br><br>
<center><form action="element_in_array.php" method="POST">
<input type="textbox" name="element">
<input type="submit" name="submit">
</form>
============================================================
input :
1) give the array values in text box
2) click in button
ex :
array :$num=array(1,2,3,4,5,6,7,8,9,10);
here 0-9 array indexes
and
1-10 array values
============================================================
output :
1) element found
2) element not found
<?php
// Checking if an Element Is in Array or not
$num=array(1,2,3,4,5,6,7,8,9,10);
$element=$_POST['element'];
if (in_array($element, $num)) {
echo 'element found';
}
else
{
echo 'element not found';
}
?>
============================================================
element_in_array_index.php :
<center><b>here checks data is in array or not</b><br><br>
<center><form action="element_in_array.php" method="POST">
<input type="textbox" name="element">
<input type="submit" name="submit">
</form>
============================================================
input :
1) give the array values in text box
2) click in button
ex :
array :$num=array(1,2,3,4,5,6,7,8,9,10);
here 0-9 array indexes
and
1-10 array values
============================================================
output :
1) element found
2) element not found
PHP Web Concepts
This session demonstrates how PHP can provide dynamic content according to browser type, randomly generated numbers or User Input. It also demonstrated how the client browser can be redirected.
Identifying Browser & Platform
PHP creates some useful environment variables that can be seen in the phpinfo.php page that was used to setup the PHP environment.
One of the environment variables set by PHP is HTTP_USER_AGENT which identifies the user's browser and operating system.
PHP provides a function getenv() to access the value of all the environment variables. The information contained in the HTTP_USER_AGENT environment variable can be used to create dynamic content appropriate to the browser.
Following example demonstrates how you can identify a client browser and operating system.
NOTE: The function preg_match () is discussed in PHP Regular expression session.
| <html> <body> <?php $viewer = getenv( "HTTP_USER_AGENT" ); $browser = "An unidentified browser"; if( preg_match( "/MSIE/i", "$viewer" ) ) { $browser = "Internet Explorer"; } else if( preg_match( "/Netscape/i", "$viewer" ) ) { $browser = "Netscape"; } else if( preg_match( "/Mozilla/i", "$viewer" ) ) { $browser = "Mozilla"; } $platform = "An unidentified OS!"; if( preg_match( "/Windows/i", "$viewer" ) ) { $platform = "Windows!"; } else if ( preg_match( "/Linux/i", "$viewer" ) ) { $platform = "Linux!"; } echo("You are using $browser on $platform"); ?> </body> </html> |
This is producing following result on my machine. This result may be different for your computer depending on what you are using.
| You are using Mozilla! on Windows! |
Display Images Randomly
The PHP rand() function is used to generate a random number. i This function can generate numbers with-in a given range. The random number generator should be seeded to prevent a regular pattern of numbers being generated. This is achieved using the srand() function that specifies the seed number as its argument.
Following example demonstrates how you can display different image each time out of four images:
| <html> <body> <?php srand( microtime() * 1000000 ); $num = rand( 1, 4 ); switch( $num ) { case 1: $image_file = "/home/images/alfa.jpg"; break; case 2: $image_file = "/home/images/ferrari.jpg"; break; case 3: $image_file = "/home/images/jaguar.jpg"; break; case 4: $image_file = "/home/images/porsche.jpg"; break; } echo "Random Image : <img src=$image_file />"; ?> </body> </html> |
Using HTML Forms
The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts.
Try out following example by putting the source code in test.php script.
| <?php if( $_POST["name"] || $_POST["age"] ) { echo "Welcome ". $_POST['name']. "<br />"; echo "You are ". $_POST['age']. " years old."; exit(); } ?> <html> <body> <form action="<?php $_PHP_SELF ?>" method="POST"> Name: <input type="text" name="name" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body> </html> |
- The PHP default variable $_PHP_SELF is used for the PHP script name and when you click "submit" button then same PHP script will be called and will produce following result:
- The method = "POST" is used to post user data to the server script. There are two methods of posting data to the server script which are discussed in PHP GET & POST chapter.
Browser Redirection
The PHP header() function supplies raw HTTP headers to the browser and can be used to redirect it to another location. The redirection script should be at the very top of the page to prevent any other part of the page from loading.
The target is specified by the Location: header as the argument to the header()function. After calling this function the exit() function can be used to halt parsing of rest of the code.
Following example demonstrates how you can redirect a browser request to another web page. Try out this example by putting the source code in test.php script.
| <?php if( $_POST["location"] ) { $location = $_POST["location"]; header( "Location:$location" ); exit(); } ?> <html> <body> <p>Choose a site to visit :</p> <form action="<?php $_PHP_SELF ?>" method="POST"> <select name="location"> <option value="http://w3c.org"> World Wise Web Consortium </option> <option value="http://www.google.com"> Google Search Page </option> </select> <input type="submit" /> </form> </body> </html> |
Displaying "File Download" Dialog Box
Sometime it is desired that you want to give option where a use will click a link and it will pop up a "File Download" box to the user in stead of displaying actual content. This is very easy and will be achived through HTTP header.
The HTTP header will be different from the actual header where we send Content-Typeas text/html\n\n. In this case content type will be application/octet-streamand actual file name will be concatenated alongwith it.
For example,if you want make a FileName file downloadable from a given link then its syntax will be as follows.
| #!/usr/bin/perl # HTTP Header print "Content-Type:application/octet-stream; name=\"FileName\"\r\n"; print "Content-Disposition: attachment; filename=\"FileName\"\r\n\n"; # Actual File Content open( FILE, "<FileName" ); while(read(FILE, $buffer, 100) ) { print("$buffer"); } |
php intruduction
Hypertext Pre-processor: What is PHP?
Hypertext Pre-processor (PHPs) is a server-side scripting language, and server-sidescripts are special commands you must place in Web pages. Those commands are processed before the pages are sent from your Server to the Web browser of your visitor. A typical PHP files will content commands to be executed in the server in addition to the usual mixture of text and HTML (Hypertext Markup Language) tags.
When you type a URL in the Address box or click a link on a Web page, you're asking a Web server on a computer somewhere to send a file to the Web browser (sometimes called a "client") on your computer. If that file is a normal HTML file, it looks exactly the same when your Web browser receives it as it did before the Web server sent it. After receiving the file, your Web browser displays its contents as a combination of text, images, and sounds. In the case of PHP page, the process is similar, except there's an extra processing step that takes place just before the Web server sends the file. Before the Web server sends the HTML file to the Web browser, it runs all server-side scripts contained in the page. Some of these scripts display the current date, time, and other information. Others process information the user has just typed into a form, such as a page in the Web site's guestbook
When you type a URL in the Address box or click a link on a Web page, you're asking a Web server on a computer somewhere to send a file to the Web browser (sometimes called a "client") on your computer. If that file is a normal HTML file, it looks exactly the same when your Web browser receives it as it did before the Web server sent it. After receiving the file, your Web browser displays its contents as a combination of text, images, and sounds. In the case of PHP page, the process is similar, except there's an extra processing step that takes place just before the Web server sends the file. Before the Web server sends the HTML file to the Web browser, it runs all server-side scripts contained in the page. Some of these scripts display the current date, time, and other information. Others process information the user has just typed into a form, such as a page in the Web site's guestbook
To distinguish them from normal HTML pages, PHP files are usually given the ".php" extension.
What Can You Do with PHP?
There are many things you can do with PHP.
- You can display date, time, and other information in different ways.
- You can make a survey form and ask people who visit your site to fill it out, send emails, save the information to a file, etc
What Do PHP pages Look Like?
The appearance of an PHP page depends on who or what is viewing it. To the Web browser that receives it, an Active Server Page looks just like a normal HTML page. If a visitor to your Web site views the source code of an PHP page, that's what they see: a normal HTML page. However, the file located in the server looks very different. In addition to text and HTML tags, you also see server-side scripts. This is what the PHP page looks like to the Web server before it is processed and sent in response to a request.
What Do PHP pages Look Like?
Server-side scripts look a lot like HTML tags. However, instead of starting and ending with lesser-than ( < ) and greater-than ( > ) brackets, they typically start with <?php or <? and will typically end with ?>. The <?php or <? are called anopening tags, and the ?> is called a closing tag. In between these tags are the server-side scripts. You can insert server-side scripts anywhere in your Web page--even inside HTML tags.
Do You Have to Be a Programmer to Understand Server-Side Scripting?
There's a lot you can do with server-side scripts without learning how to program. For this reason, much of the online Help for PHP is written for people who are familiar with HTML but aren't computer programmers.