Count 範例

if(count($_POST)>0 && $_POST[“submit"]=="Count") {

$pdoStatement = $pdo->prepare(“SELECT Count(*) as count FROM address_book“);
$pdoStatement->execute();

//撈資料
while($row = $pdoStatement->fetch(PDO::FETCH_ASSOC) ) {
echo “count=".$row[count];
}
}

[第五堂] PHP POST & GET 九九乘法範例

GET    http://140.112.31.82/example.php?val=9

<?php
if(count($_GET)>0){
for($i=1;$i<=$_GET[“val"];$i++){
for($j=1;$j<=$_GET[“val"];$j++){
echo “$i*$j=".$i*$j."<br>";
}
echo “=======<br>";
}
}
?>

POST    http://140.112.31.82/example2.php

<form action="" method="post" name="form1″><br>
Please input value:
<input name="val" type="text" value="9″>
<input name="submit" type="submit" value="ok"><br>

<?php
if(count($_POST)>0){
for($i=1;$i<=$_POST[“val"];$i++){
for($j=1;$j<=$_POST[“val"];$j++){
echo “$i*$j=".$i*$j."<br>";
}
echo “=======<br>";
}
}
?>

[第四堂] php & sqlite 範例

<form action="" method="post" name="form1″><br>
Input address book data:<br>
<input name="name" type="text" value="shinder"><br>
<input name="phone" type="text" value="0918981520″><br>
<input name="address" type="text" value="Taipei"><br>
<input name="submit" type="submit" value="Add"><br>

<?php

//建立資料連線物件
$pdo = new PDO(“sqlite:mydb.sqlite");

$pdo->exec(“CREATE TABLE address_book (
sid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,
name VARCHAR,
phone VARCHAR,
address VARCHAR,
creation_date DATETIME DEFAULT CURRENT_TIMESTAMP)");
if(count($_POST)>0) {
// 準備新增資料的語法
$name = $_POST[“name"];
$phone = $_POST[“phone"];
$address = $_POST[“address"];
$pdo->exec(“INSERT INTO ‘address_book’ (‘name’, ‘phone’, ‘address’ )
VALUES( ‘$name’, ‘$phone’, ‘$address’)");
}

$pdoStatement = $pdo->prepare(“SELECT * FROM address_book");
$pdoStatement->execute();
$arr;
while($row = $pdoStatement->fetch(PDO::FETCH_ASSOC) ) {
print_r( $row );
}