Your SlideShare is downloading. ×
0
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Total PHP
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Total PHP

2,412

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,412
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
53
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Introduction to Open source PHP & Joomla Asst. Prof Roshni M. Raval
  • 2.  
  • 3. What You Should Already Know <ul><li>HTML/XHTML </li></ul><ul><li>JavaScript </li></ul><ul><li>CSS </li></ul>
  • 4. HTML For describing web pages
  • 5. What is HTML? <ul><li>HTML stands for H yper T ext M arkup L anguage </li></ul><ul><li>For describing web pages. </li></ul><ul><li>Not a programming language, it is a markup language </li></ul><ul><li>A markup language is a set of markup tags </li></ul><ul><li>HTML follows w3c rules. </li></ul><ul><li>Div based code. </li></ul>
  • 6. Java Script Is a Library for interactive UI and client side validation
  • 7. Why JavaScript? <ul><li>JavaScript is a scripting language </li></ul><ul><li>JavaScript was designed to add interactivity to HTML pages </li></ul><ul><li>Lightweight programming language </li></ul><ul><li>Embedded directly into HTML pages </li></ul><ul><li>Interpreted language (means that scripts execute without preliminary compilation) </li></ul><ul><li>Everyone can use JavaScript without purchasing a license </li></ul><ul><li>jQuery </li></ul>
  • 8. ..continue <ul><li>JavaScript is the most popular scripting language on the internet, and works in all major browsers, such as. </li></ul><ul><li>Internet Explorer </li></ul><ul><li>Firefox, </li></ul><ul><li>Chrome, </li></ul><ul><li>Opera, </li></ul><ul><li>and Safari. </li></ul>
  • 9. What JavaScript can do? <ul><li>JavaScript gives HTML designers a programming tool. </li></ul><ul><li>Can put dynamic text into an HTML page. </li></ul><ul><li>Can react to events. </li></ul><ul><li>Can read and write HTML elements. </li></ul><ul><li>Can be used to validate data. </li></ul><ul><li>Can be used to create cookies. </li></ul>
  • 10. CSS CSS stands for C ascading S tyle S heets
  • 11. What is CSS? <ul><li>Styles define how to display HTML elements. </li></ul><ul><li>External Style Sheets can save a lot of work. </li></ul><ul><li>External Style Sheets are stored in CSS files. </li></ul>
  • 12. PHP H ypertext P re p rocessor
  • 13. PHP Introduction <ul><li>PHP is a server-side scripting language. </li></ul><ul><li>PHP is a powerful tool for making dynamic and interactive Web pages. </li></ul><ul><li>PHP is the widely-used, free, and efficient alternative to competitors such as Microsoft&apos;s ASP. </li></ul><ul><li>Script execution results are sent to a browser as an HTML page </li></ul><ul><li>PHP is a type-less language </li></ul>
  • 14. PHP Structure <ul><li>Tradition: Start with an HTML file </li></ul><ul><li>Add special tags to separate PHP code from HTML statements </li></ul><ul><li>(i.e. &lt;?php </li></ul><ul><li>…… </li></ul><ul><li>?&gt;) </li></ul><ul><li>Web server parses the PHP file, producing HTML </li></ul>
  • 15. Example: myfirst.php <ul><ul><li>&lt;html&gt; </li></ul></ul><ul><ul><li>&lt;body&gt; </li></ul></ul><ul><ul><li>&lt;?php </li></ul></ul><ul><ul><li>//A comment </li></ul></ul><ul><ul><li>/*Or comment like this*/ </li></ul></ul><ul><ul><li>print(&amp;quot;&lt;b&gt;Hello world&lt;/b&gt;&amp;quot;); </li></ul></ul><ul><ul><li>$v = 5; </li></ul></ul><ul><ul><li>print(&amp;quot;&lt;p&gt;Hello again &amp;quot; . $v ); </li></ul></ul><ul><ul><li>print(&amp;quot;&lt;p&gt;Hello a third time $v&amp;quot;); </li></ul></ul><ul><ul><li>?&gt; </li></ul></ul><ul><ul><li>&lt;/body&gt; </li></ul></ul><ul><ul><li>&lt;/html&gt; </li></ul></ul>
  • 16. Variables <ul><li>All variables start with a dollar sign, $ </li></ul><ul><ul><li>$u = 5; </li></ul></ul><ul><ul><li>$v = “hello”; </li></ul></ul><ul><ul><li>$w = 1.22; </li></ul></ul><ul><ul><li>$x = $u + $v; //arithmetic with + - ONLY </li></ul></ul><ul><ul><li>$y = $v . $v; //concatenation with period operator </li></ul></ul><ul><ul><li>$x = $u . $u; //produces 55, not 10 </li></ul></ul>
  • 17. Printing <ul><ul><li>$u = 5; </li></ul></ul><ul><ul><li>print( “5 hello” ); //print anything in quotes </li></ul></ul><ul><ul><li>print( $u . “hello” ); //prints 5hello </li></ul></ul><ul><ul><li>print( “$u Hello” ); //prints 5 Hello </li></ul></ul><ul><ul><li>echo ‘Hello’; </li></ul></ul><ul><ul><li>echo ‘Hello’ . $u; </li></ul></ul>
  • 18. String-Related Functions <ul><ul><li>$v = “hello”; </li></ul></ul><ul><ul><li>strlen( $v); //returns 5 </li></ul></ul><ul><ul><li>trim( $v); //trims any spaces on either side of a string </li></ul></ul><ul><ul><li>$x = strtolower ($v); //$x has hello </li></ul></ul><ul><ul><li>$x = strtoupper($v); //$x has HELLO </li></ul></ul><ul><ul><li>$str = “abcdef”; </li></ul></ul><ul><ul><li>$a = substr( $str, 3, 3 ); </li></ul></ul># of characters to copy Start position, zero indexed Source string “ def” Can be negative to start from right side
  • 19. Getting HTML Form Data <ul><li>There are 3 ways to get form data in PHP </li></ul><ul><ul><li>Global variables – this is a bad way because of security problems. PHP creates a variable with a name matching the form field name in the source HTML. </li></ul></ul><ul><ul><li>POST variable associative array </li></ul></ul><ul><ul><ul><li>Prior to version 4.1, $HTTP_POST_VARS </li></ul></ul></ul><ul><ul><ul><li>4.1 and after, </li></ul></ul></ul><ul><ul><ul><li>$_POST </li></ul></ul></ul><ul><ul><li>GET variable associative array </li></ul></ul><ul><ul><ul><li>Same as POST, but use GET </li></ul></ul></ul>
  • 20. Examples <ul><li>Global variables (HTML has field with name ‘abc’) </li></ul><ul><ul><ul><li>print ($abc); </li></ul></ul></ul><ul><li>POST </li></ul><ul><ul><ul><li>print($_POST(‘abc’)); //4.1 and after </li></ul></ul></ul><ul><li>GET </li></ul><ul><ul><ul><li>print($_GET(‘abc’)); //4.1 and after </li></ul></ul></ul>
  • 21. Comparing Strings <ul><li>strcmp( $a, $b ); //works like C function </li></ul><ul><li>Returns: </li></ul><ul><li> – 1 if first string less than second string </li></ul><ul><li> 0 if the same </li></ul><ul><li>1 if first string greater than second string </li></ul><ul><li>It is case sensitive </li></ul>
  • 22. PHP Syntax Similarities <ul><li>Has a switch statement </li></ul><ul><li>for loop is the same, but uses PHP variable syntax </li></ul><ul><ul><li>for ($i=0; $i &lt; 10; $i++ ){ …. } </li></ul></ul><ul><li>while and if are also what you’d expect </li></ul><ul><li>Standard logical operators: ==, &amp;&amp;, &lt;, &gt; … </li></ul>
  • 23. Other Useful Functions <ul><li>round ($a); //rounds a number </li></ul><ul><li>is_numeric($v); //returns true/false </li></ul><ul><li>rand($start, $end); //Produces int rand </li></ul>
  • 24. Creating Functions <ul><ul><li>function myfunc( $a, $b, $c ) { </li></ul></ul><ul><ul><li>//this is my code </li></ul></ul><ul><ul><li>return $x; </li></ul></ul><ul><ul><li>} </li></ul></ul>
  • 25. External PHP Files <ul><li>Can use require or include </li></ul><ul><ul><li>Require will produce a fatal error if the file cannot be found </li></ul></ul><ul><ul><li>Include will just ignore a missing script file </li></ul></ul><ul><ul><li>require(‘my.php’); </li></ul></ul><ul><ul><li>include(‘my.php’); </li></ul></ul><ul><ul><li>The files can contain PHP and/or HTML </li></ul></ul>
  • 26. Arrays <ul><li>Creating an array </li></ul><ul><ul><li>$a = array(1,2,3,4,5); </li></ul></ul><ul><li>Accessing array elements </li></ul><ul><ul><li>$v = $a[2]; </li></ul></ul><ul><ul><li>$a[2] = 5; </li></ul></ul><ul><ul><li>$a[] = 1; $a[] = 2; $a[] = 3; //appends to array </li></ul></ul>
  • 27. Iterating Over Arrays <ul><ul><li>for ($i=0; $i&lt;count($a); $i++ ) { </li></ul></ul><ul><ul><li>print ($a[i]); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>foreach( $a as $item ) { </li></ul></ul><ul><ul><li>print( “&lt;p&gt;$item”); </li></ul></ul><ul><ul><li>} </li></ul></ul>Array variable Local variable. Set to next array element each iteration.
  • 28. Other Array Functions <ul><ul><li>$m = max($a); //returns max value in array </li></ul></ul><ul><ul><li>$m = min($a); //returns min value in array </li></ul></ul><ul><ul><li>$s = array_sum($a); //returns sum or array values </li></ul></ul><ul><ul><li>sort($a); //sorts the items in the array. Changes </li></ul></ul><ul><ul><li>//the array itself </li></ul></ul><ul><ul><li>Optional second argument is “sort flags” to control the sort. </li></ul></ul>
  • 29. Associative Arrays <ul><li>Arrays containing key/value pairs </li></ul><ul><ul><li>$s = array( ‘a’=&gt;’alpha’, ‘b’=&gt;’beta’, … ); </li></ul></ul><ul><ul><li>print ( $s[‘b’] ); </li></ul></ul><ul><li>The parameter to the left of =&gt; is the key. </li></ul><ul><li>The right parameter is the value. </li></ul>
  • 30. SQL – Structured Query Language <ul><li>A language for accessing relational databases </li></ul><ul><li>Relational databases have tables </li></ul><ul><li>Tables have fields and contain rows of data </li></ul>
  • 31. SQL Syntax – SELECT <ul><li>Used for retrieving data from a database </li></ul><ul><ul><li>SELECT [fields] FROM [tables] WHERE [expr] </li></ul></ul><ul><ul><li>Examples </li></ul></ul><ul><ul><li>select * from users </li></ul></ul><ul><ul><li>select abc, def from mytable where ghi=5 </li></ul></ul>
  • 32. SQL Syntax – INSERT <ul><li>Used to insert new data in a table </li></ul><ul><ul><li>INSERT INTO [table] [field names] VALUES [values] </li></ul></ul><ul><ul><li>Examples </li></ul></ul><ul><ul><li>insert into users (abc,def,ghi) values (‘111’,22,’cc) </li></ul></ul><ul><ul><li>insert into xyz values (1,2,3,4,5) </li></ul></ul>
  • 33. SQL Syntax – UPDATE <ul><li>Updating one or more values in existing rows in a table </li></ul><ul><ul><li>UPDATE [table] SET [name=value pairs] WHERE [expression] </li></ul></ul><ul><ul><li>Examples </li></ul></ul><ul><ul><li>update mytable set a=‘aaa’, b=55 where c=11 </li></ul></ul>
  • 34. PHP and MySQL Database <ul><li>5 steps </li></ul><ul><ul><li>Connect to the Mysql DBMS </li></ul></ul><ul><ul><li>Pick a database </li></ul></ul><ul><ul><li>Execute an SQL statement </li></ul></ul><ul><ul><li>If the SQL was a ‘select’, retrieve the data </li></ul></ul><ul><ul><li>Close the connection </li></ul></ul>
  • 35. Connecting to MySQL DBMS <ul><ul><li>$con = mysql_connect( /* 3 arguments */ ); </li></ul></ul><ul><ul><li>Your MySQL DBMS server process network location </li></ul></ul><ul><ul><li>Your MySQL user ID </li></ul></ul><ul><ul><li>Your MySQL user password </li></ul></ul><ul><ul><li>For tonight only, </li></ul></ul><ul><ul><li>mysql_connect(‘www.freesql.org’,’upeworkshop’,’upeworkshop’); </li></ul></ul>
  • 36. Selecting a Database <ul><ul><li>mysql_select_db( ‘upeworkshop’ ); </li></ul></ul>
  • 37. Executing an SQL Statement <ul><ul><li>mysql_query( /*SQL statement*/ ); </li></ul></ul><ul><ul><li>Proper form for any SQL not a Select </li></ul></ul><ul><ul><li>if ( !mysql_query ( “update a ….” ); ) { </li></ul></ul><ul><ul><li>echo mysql_error(); //for easy debugging, not for final user-oriented website </li></ul></ul><ul><ul><li>} //returns true/false if it worked, or not </li></ul></ul>
  • 38. For Select SQL Statements <ul><ul><li>$r = mysql_query( ‘select * from abc’ ); </li></ul></ul><ul><ul><li>while ( $row = mysql_fetch_row( $r ) ) { … } </li></ul></ul><ul><ul><li>$row contains a row of data </li></ul></ul><ul><ul><li>returns false when no more rows available </li></ul></ul><ul><ul><li>Iterating through the fields in the row </li></ul></ul><ul><ul><li>foreach ( $row as $item ) { … } </li></ul></ul><ul><ul><li>OR access the fields using index position (zero indexed) </li></ul></ul><ul><ul><li>OR put results in an associative array – less error prone </li></ul></ul><ul><ul><li>while ($row = mysql_fetch_assoc($r)){ </li></ul></ul><ul><ul><li>echo $row[‘firstname’]; </li></ul></ul><ul><ul><li>} </li></ul></ul>
  • 39. Closing a Connection <ul><ul><li>mysql_close( $con ); </li></ul></ul>
  • 40. What is other than core PHP ?
  • 41. What is CMS? <ul><li>A content management system is software that keeps track of every piece of content on your Web site, much like your local public library keeps track of books and stores them. </li></ul><ul><li>Content can be simple text, photos, music, video, documents, or just about anything you can think of. </li></ul>
  • 42. Famous CMS
  • 43. Joomla <ul><li>Joomla is an free and open source content management system (CMS), which enables you to build Web sites and powerful online applications. </li></ul><ul><li>Extensible </li></ul><ul><li>Written in PHP </li></ul><ul><li>It uses OOP techniques </li></ul><ul><li>Based on MVC framework. </li></ul>
  • 44. Real world examples <ul><li>Corporate Web sites or portals </li></ul><ul><li>Online magazines, newspapers, and publications </li></ul><ul><li>E-commerce and online reservations </li></ul><ul><li>Government applications </li></ul><ul><li>Small business Web sites </li></ul><ul><li>Non-profit and organizational Web sites </li></ul><ul><li>Community-based portals </li></ul>
  • 45. Servers <ul><li>WAMP </li></ul><ul><li>LAMP </li></ul><ul><li>MAMP </li></ul><ul><li>XAMPP </li></ul>
  • 46. Source <ul><li>HTML/CSS/JS : http://www.w3schools.com </li></ul><ul><li>PHP : http://www.php.net </li></ul><ul><li>MySQL : http://www.mysql.com </li></ul><ul><li>Server : http://www.wampserver.com </li></ul><ul><li>Joomla : http://www.joomla.org/ </li></ul>
  • 47. &nbsp;

×