58回目授業内容 WordPressインストール方法〜PHP+DBで本格的なWebシステムを作る〜脱線
[授業][Dreamweaver][PHP]
WordPress
- テーブル接頭辞「wp_」
- ロリポップ等の元々サービスしているところとぶつかる
- なのでテーブル名を変える・「wp1_」
- テーマを選ぶ
- 一般設定で「デフォルト管理グループ」を設定することで一つ一つの記事に権限をつけれる
- 会社向け・一般向けの記事を作れる
PHP+DBで本格的なWebシステムを作るー続き!
- 最初・最終ページの設定(ページング)
<?php require('dbconnect.php'); $page = $_REQUEST['page']; if ($page =='') { $page = 1; } $page = max($page, 1); //最終ページを取得する $sql = 'SELECT COUNT(*) AS cnt FROM my_items'; $recordSet = mysql_query($sql); $table = mysql_fetch_assoc($recordSet); $maxPage = ceil($table['cnt'] / 5); $page = min($page, $maxPage); $start = ($page - 1) * 5; $recordSet = mysql_query('SELECT m.name, i.* FROM makers m, my_items i WHERE m.id=i.maker_id ORDER BY id DESC LIMIT ' . $start . ',5'); ?> <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <title>一覧画面</title> <link href="style.css" rel="stylesheet" media="screen, print"> </head> <table width="100%"> <tr> <th scope="col">ID</th> <th scope="col">メーカー</th> <th scope="col">商品名</th> <th scope="col">価格</th> </tr> <?php while ($table = mysql_fetch_assoc($recordSet)) { ?> <tr> <td><?php print(htmlspecialchars($table['id'])); ?></td> <td><?php print(htmlspecialchars($table['name'])); ?></td> <td><?php print(htmlspecialchars($table['item_name'])); ?></td> <td><?php print(htmlspecialchars($table['price'])); ?></td> </tr> <?php } ?> </table> <ul class="paging"> <?php if ($page >1) { ?> <li><a href="index.php?page=<?php print($page - 1); ?>">前のページへ</a></li> <?php } else { ?> <li>前のページへ</li> <?php } ?> <?php if ($page < $maxPage) { ?> <li><a href="index.php?page=<?php print($page + 1); ?>">次のページへ</a></li> <?php } else { ?> <li>次のページへ</li> <?php } ?> </ul> <body> </body> </html>
- 間違えたデータを編集するー編集画面
update.php
<?php require('dbconnect.php'); $id = $_REQUEST['id']; $sql = sprintf("SELECT * FROM my_items WHERE id=%d", mysql_real_escape_string($id) ); $recordSet = mysql_query($sql); $data = mysql_fetch_assoc($recordSet); ?> <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <title>データ変更画面</title> <link href="style.css" rel="stylesheet" media="screen, print"> </head> <body> <p>変更する内容を記入して下さい。</p> <form id="frmUpdate" name="frmUpdate" method="post" action="update_do.php"> <dl> <dt> <label for="maker_id">メーカーID</label> </dt> <dd> <input name="maker_id" type="text" id="maker_id" size="10" maxlength="10" value="<?php print(htmlspecialchars($data['maker_id'], ENT_QUOTES)); ?>"> </dd> <dt> <label for="item_name">商品名</label> </dt> <dd> <input name="item_name" type="text" id="item_name" size="35" maxlength="255" value="<?php print(htmlspecialchars($data['item_name'], ENT_QUOTES)); ?>"> </dd> <dt> <label for="price">価格</label> </dt> <dd> <input name="price" type="text" id="price" size="10" maxlength="10" value="<?php print(htmlspecialchars($data['price'], ENT_QUOTES)); ?>"> 円</dd> <dt> <label for="keyword">キーワード</label> </dt> <dd> <input name="keyword" type="text" id="keyword" size="50" maxlength="255" value="<?php print(htmlspecialchars($data['keyword'], ENT_QUOTES)); ?>"> </dd> </dl> <input type="submit" value="変更する"> <input type="hidden" name="id" value="<?php print(htmlspecialchars($data['id'], ENT_QUOTES)) ?>"> </form> </body> </html>
- index.phpに次の文面を足す
<p><a href="input.php">新しい商品を登録する</a></p>
<th scope="col">編集・削除</th>
<td><a href="update.php?id=<?php print(htmlspecialchars($table['id']));?>">編集・</a><a href="delete.php?id=<?php print(htmlspecialchars($table['id']));?>">削除</a></td>
- 各変更確認画面phpに次の文面を追記する
<a href="index.php">戻る</a>