際際滷

際際滷Share a Scribd company logo
慮亮旅凌粒溜留 留亮凌粒ホ WEB
亮竜 PHP
里旅 竜溜僚留旅 慮 PHP;
  痢痢 竜溜僚留旅 亮旅留 粒了マ留 script 留 慮僚
了竜略 凌 隆旅留虜凌亮旅旅 , 竜隆旅留亮龍僚慮 竜旅隆旅虜略
 粒旅留 凌 Web .龍留 竜 亮旅留 HTML 竜了溜隆留
亮凌竜溜竜 僚留 竜僚亮留マ竜竜 PHP 虜ホ肝肯採 ,
 凌 虜留 竜虜竜了竜溜留旅 虜略虜竜 凌略 凌 虜留
竜旅虜龍竜竜 慮 竜了溜隆留.  痢痢 虜ホ肝肯採穎
 亮竜留略侶竜竜 凌 Web 隆旅留虜凌亮旅旅 虜留旅
隆慮亮旅凌粒竜溜 HTML 旅 略了了慮 龍両凌隆凌 凌 虜留 隆竜旅 凌
 竜旅虜龍慮.
里旅 竜溜僚留旅 慮 MySQL;
  MySQL 竜溜僚留旅 龍僚留 凌了 粒旅粒凌凌 虜留旅 隆僚留
, 慮亮留 隆旅留竜溜旅慮 硫略竜僚 隆竜隆凌亮龍僚僚. 旅留
硫略慮 隆竜隆凌亮龍僚僚 留 竜旅龍竜旅 僚留 留凌慮慮虜竜竜竜
, 僚留 留僚留侶慮略竜 , 僚留 留両旅僚凌亮竜溜竜 虜留旅 僚留 留僚留虜留了竜溜竜
留 隆竜隆凌亮龍僚留 留凌竜了竜亮留旅虜略 .  MySQL
隆旅留虜凌亮旅旅竜了龍粒竜旅 慮僚 硫留慮 留 隆竜隆凌亮龍僚留
留 , 粒旅留 僚留 亮凌凌僚 僚留 隆凌了竜凌僚 凌了了凌溜
旅竜 留凌僚留 , 粒旅留 僚留 留龍竜旅 粒旅粒凌慮
硫留慮 虜留旅 僚留 隆旅留留了溜侶竜旅 旅 亮僚凌
旅凌凌旅慮亮龍僚凌旅 旅竜 亮凌凌僚 僚留 龍凌僚
硫留慮.
了竜凌僚竜虜旅亮留留 PHP
 凌  溜僚留旅 隆竜略僚
 虜亮略虜慮慮  硫留溜侶竜留旅 慮僚 C 虜留旅 Perl
 竜留竜旅亮慮留  隆旅留虜龍旅亮慮 粒旅留 凌了了略
了竜旅凌粒旅虜略
 慮粒留溜凌 ホ肝肯採穎  僚凌旅虜 了凌粒旅亮旅虜
了竜凌僚竜虜旅亮留留 MySQL






隆凌慮
凌  竜略僚
虜凌了溜留 旅慮
竜留竜旅亮慮留
旅留虜龍旅亮凌 慮粒留溜凌 虜ホ肝肯採穎
粒虜留略留慮 律AMPP
 竜旅硫略了了凌僚 凌 竜僚亮留ホ塾砧 了竜 旅
留留留溜慮竜 竜僚凌了凌粒溜竜:
 Linux host
 Apache server
 MySQL database server
 PhP scripting language
+ 虜凌了溜留 竜粒虜留略留慮
 虜凌了溜留 留留亮竜凌凌溜慮慮
 虜凌了溜留 隆旅留竜溜旅慮 慮竜旅ホ
 旅 留留留溜慮留 凌旅 竜了竜留溜竜 隆旅留虜龍旅亮竜
竜虜隆竜旅 僚 竜留亮凌粒ホ 虜留旅 略僚旅留
留慮亮竜 亮竜 凌 竜旅硫略了了凌僚 凌 web hoster.
 竜僚 凌竜溜僚竜留旅 粒旅留 OffLine Server.
If else statement
Set $a, $b manually!
<?php
if ($a > $b) {
echo "a is bigger than b";
} elseif ($a == $b) {
echo "a is equal to b";
} else {
echo "a is smaller than b";
}
?>
While statement
 <?php
/* example 1 */
$i = 1;
while ($i <= 10) {
echo $i++; /* the printed value would be
$i before the increment
(post-increment) */
}

?>
While statement (2)
 /* example 2 */
<?php
$i = 1;
while ($i <= 10) {
echo $i;
$i++;
}
?>
List statement
<?php
$info = array('coffee', 'brown', 'caffeine');
// Listing all the variables
list($drink, $color, $power) = $info;
echo "$drink is $color and $power makes it special.n";
// Listing some of them
list($drink, , $power) = $info;
echo "$drink has $power.n";
// Or let's skip to only the third one
list( , , $power) = $info;
echo "I need $power!n";
// list() doesn't work with strings
list($bar) = "abcde";
var_dump($bar); // NULL
?>
Each statement (arrays)
 <?php
$foo = array("bob", "fred", "jussi", "jouni", "eg
on", "marliese");
$bar = each($foo);
print_r($bar);
?>
foreach statement
 <?php
$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
$value = $value * 2;
}
// $arr is now array(2, 4, 6, 8)
unset($value); // break the reference with the
last element
?>
Exercise
 Repeat a paragraph according to an input value.
For example: $p=3
This is a paragraph
This is a paragraph
This is a paragraph
 Print the square value if read a even integer
Or Print the cubic value if read a odd integer
Or print as it is if read a string.
Create DB (phpmyadmin)







DB name: roubel
DB user: rb_user1
DB psw: myuser1
Host: localhost
Create table: orders
(4 columns: orderid(PK), oil, spark, tyres)
Connect to database
// Create connection
$con=mysqli_connect("localhost","rb_user1"
,"myuser1","roubel");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " .
mysqli_connect_error();
} else { echo "Connection was OK!n";}
Database query
Exercise: Insert variables instead of values
mysql_select_db($dbname, $con) or die
($dbname . " Database not found." . $dbuser);
Handle database result functions
//randomly select one row
$query = "SELECT * FROM `order` WHERE 1";
$result = mysqli_query($con, $query);
$num_results = mysqli_num_rows($result);
echo $num_results;
$result = mysqli_query($con, $query) or
die(mysqli_error($con));
Show array values
$info = mysqli_fetch_all( $result );
//$info = mysqli_fetch_array( $result ); //check it
echo '<br />';
foreach ($info[0] as $value) { echo "Value:
$value<br />n"; };
foreach ($info[1] as $value) { echo "Value:
$value<br />n"; };
Ask 1 orders tyres quantity
$query = "SELECT `orderid` , `oil` , `tyres` , `sparks`
FROM `order` WHERE `orderid` =1 LIMIT 0 , 30";
$result = mysqli_query($con, $query);
$info2 = mysqli_fetch_array( $result );
$tyres = $info2['tyres'];
echo '<br>tyres from order 1: '.$tyres;
Use list to fetch data






list(,$oilqty, $tyreqty, $sparksqty) = $info2;
echo '<br>';
echo '<br>oil from order 1: '.$oilqty;
echo '<br>tyres from order 1: '.$tyreqty;
echo '<br>sparks from order 1: '.$sparksqty;
Close connection
//connection to database no longer needed
mysqli_close($con);
Reuse code using functions
Create functions.php
function askDB($query)
{
.. Code .
return $info;
}
Include functions.php within php area
include functions.php';
Call fuction
$var = askDB($query);
Session handling
For all session pages!
session_start();
if (isset($_SESSION['mydog']))
{..code
}
else
{error printout..
}
Printf  sprintf (formatted printout)
 <?php
$num = 5;
$location = 'tree';

$format = 'There are %d monkeys in the %s';
echo sprintf($format, $num, $location);
?>

More Related Content

Php basics

  • 2. 里旅 竜溜僚留旅 慮 PHP; 痢痢 竜溜僚留旅 亮旅留 粒了マ留 script 留 慮僚 了竜略 凌 隆旅留虜凌亮旅旅 , 竜隆旅留亮龍僚慮 竜旅隆旅虜略 粒旅留 凌 Web .龍留 竜 亮旅留 HTML 竜了溜隆留 亮凌竜溜竜 僚留 竜僚亮留マ竜竜 PHP 虜ホ肝肯採 , 凌 虜留 竜虜竜了竜溜留旅 虜略虜竜 凌略 凌 虜留 竜旅虜龍竜竜 慮 竜了溜隆留. 痢痢 虜ホ肝肯採穎 亮竜留略侶竜竜 凌 Web 隆旅留虜凌亮旅旅 虜留旅 隆慮亮旅凌粒竜溜 HTML 旅 略了了慮 龍両凌隆凌 凌 虜留 隆竜旅 凌 竜旅虜龍慮.
  • 3. 里旅 竜溜僚留旅 慮 MySQL; MySQL 竜溜僚留旅 龍僚留 凌了 粒旅粒凌凌 虜留旅 隆僚留 , 慮亮留 隆旅留竜溜旅慮 硫略竜僚 隆竜隆凌亮龍僚僚. 旅留 硫略慮 隆竜隆凌亮龍僚僚 留 竜旅龍竜旅 僚留 留凌慮慮虜竜竜竜 , 僚留 留僚留侶慮略竜 , 僚留 留両旅僚凌亮竜溜竜 虜留旅 僚留 留僚留虜留了竜溜竜 留 隆竜隆凌亮龍僚留 留凌竜了竜亮留旅虜略 . MySQL 隆旅留虜凌亮旅旅竜了龍粒竜旅 慮僚 硫留慮 留 隆竜隆凌亮龍僚留 留 , 粒旅留 僚留 亮凌凌僚 僚留 隆凌了竜凌僚 凌了了凌溜 旅竜 留凌僚留 , 粒旅留 僚留 留龍竜旅 粒旅粒凌慮 硫留慮 虜留旅 僚留 隆旅留留了溜侶竜旅 旅 亮僚凌 旅凌凌旅慮亮龍僚凌旅 旅竜 亮凌凌僚 僚留 龍凌僚 硫留慮.
  • 4. 了竜凌僚竜虜旅亮留留 PHP 凌 溜僚留旅 隆竜略僚 虜亮略虜慮慮 硫留溜侶竜留旅 慮僚 C 虜留旅 Perl 竜留竜旅亮慮留 隆旅留虜龍旅亮慮 粒旅留 凌了了略 了竜旅凌粒旅虜略 慮粒留溜凌 ホ肝肯採穎 僚凌旅虜 了凌粒旅亮旅虜
  • 5. 了竜凌僚竜虜旅亮留留 MySQL 隆凌慮 凌 竜略僚 虜凌了溜留 旅慮 竜留竜旅亮慮留 旅留虜龍旅亮凌 慮粒留溜凌 虜ホ肝肯採穎
  • 6. 粒虜留略留慮 律AMPP 竜旅硫略了了凌僚 凌 竜僚亮留ホ塾砧 了竜 旅 留留留溜慮竜 竜僚凌了凌粒溜竜: Linux host Apache server MySQL database server PhP scripting language
  • 7. + 虜凌了溜留 竜粒虜留略留慮 虜凌了溜留 留留亮竜凌凌溜慮慮 虜凌了溜留 隆旅留竜溜旅慮 慮竜旅ホ 旅 留留留溜慮留 凌旅 竜了竜留溜竜 隆旅留虜龍旅亮竜 竜虜隆竜旅 僚 竜留亮凌粒ホ 虜留旅 略僚旅留 留慮亮竜 亮竜 凌 竜旅硫略了了凌僚 凌 web hoster. 竜僚 凌竜溜僚竜留旅 粒旅留 OffLine Server.
  • 8. If else statement Set $a, $b manually! <?php if ($a > $b) { echo "a is bigger than b"; } elseif ($a == $b) { echo "a is equal to b"; } else { echo "a is smaller than b"; } ?>
  • 9. While statement <?php /* example 1 */ $i = 1; while ($i <= 10) { echo $i++; /* the printed value would be $i before the increment (post-increment) */ } ?>
  • 10. While statement (2) /* example 2 */ <?php $i = 1; while ($i <= 10) { echo $i; $i++; } ?>
  • 11. List statement <?php $info = array('coffee', 'brown', 'caffeine'); // Listing all the variables list($drink, $color, $power) = $info; echo "$drink is $color and $power makes it special.n"; // Listing some of them list($drink, , $power) = $info; echo "$drink has $power.n"; // Or let's skip to only the third one list( , , $power) = $info; echo "I need $power!n"; // list() doesn't work with strings list($bar) = "abcde"; var_dump($bar); // NULL ?>
  • 12. Each statement (arrays) <?php $foo = array("bob", "fred", "jussi", "jouni", "eg on", "marliese"); $bar = each($foo); print_r($bar); ?>
  • 13. foreach statement <?php $arr = array(1, 2, 3, 4); foreach ($arr as &$value) { $value = $value * 2; } // $arr is now array(2, 4, 6, 8) unset($value); // break the reference with the last element ?>
  • 14. Exercise Repeat a paragraph according to an input value. For example: $p=3 This is a paragraph This is a paragraph This is a paragraph Print the square value if read a even integer Or Print the cubic value if read a odd integer Or print as it is if read a string.
  • 15. Create DB (phpmyadmin) DB name: roubel DB user: rb_user1 DB psw: myuser1 Host: localhost Create table: orders (4 columns: orderid(PK), oil, spark, tyres)
  • 16. Connect to database // Create connection $con=mysqli_connect("localhost","rb_user1" ,"myuser1","roubel"); // Check connection if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } else { echo "Connection was OK!n";}
  • 17. Database query Exercise: Insert variables instead of values mysql_select_db($dbname, $con) or die ($dbname . " Database not found." . $dbuser);
  • 18. Handle database result functions //randomly select one row $query = "SELECT * FROM `order` WHERE 1"; $result = mysqli_query($con, $query); $num_results = mysqli_num_rows($result); echo $num_results; $result = mysqli_query($con, $query) or die(mysqli_error($con));
  • 19. Show array values $info = mysqli_fetch_all( $result ); //$info = mysqli_fetch_array( $result ); //check it echo '<br />'; foreach ($info[0] as $value) { echo "Value: $value<br />n"; }; foreach ($info[1] as $value) { echo "Value: $value<br />n"; };
  • 20. Ask 1 orders tyres quantity $query = "SELECT `orderid` , `oil` , `tyres` , `sparks` FROM `order` WHERE `orderid` =1 LIMIT 0 , 30"; $result = mysqli_query($con, $query); $info2 = mysqli_fetch_array( $result ); $tyres = $info2['tyres']; echo '<br>tyres from order 1: '.$tyres;
  • 21. Use list to fetch data list(,$oilqty, $tyreqty, $sparksqty) = $info2; echo '<br>'; echo '<br>oil from order 1: '.$oilqty; echo '<br>tyres from order 1: '.$tyreqty; echo '<br>sparks from order 1: '.$sparksqty;
  • 22. Close connection //connection to database no longer needed mysqli_close($con);
  • 23. Reuse code using functions Create functions.php function askDB($query) { .. Code . return $info; } Include functions.php within php area include functions.php'; Call fuction $var = askDB($query);
  • 24. Session handling For all session pages! session_start(); if (isset($_SESSION['mydog'])) {..code } else {error printout.. }
  • 25. Printf sprintf (formatted printout) <?php $num = 5; $location = 'tree'; $format = 'There are %d monkeys in the %s'; echo sprintf($format, $num, $location); ?>