phpで作ってデータベース(Mysql)に保存してあるデータをidごと別々にhtmlにて書き出したいですが可能でしょうか?
したいことは、管理画面に表示されているidごとの項目にstg同期ボタンがあって、それを押すとid.htmlとしてそれぞれ書き出したいです。
例えば、100.htmlとして、一つのユーザーが観れるhtmlページを書き出したいです。
例2:データベースに
test_id, test_title, test_contents, test_date.test_imageのデータを保存しています。このデータのid毎にhtmlにて書き出したいです。WordPressやMovable Typeとかに似ているイメージです。
例えば:添付した画像test3の書き出すボタンを押すと/Applications/MAMP/htdocs/test/のディレクトリーの下に書き出したいです
/Applications/MAMP/htdocs/test/1.html
/Applications/MAMP/htdocs/test/2.html
1.htmlと2.htmlにデータベースに保存されているtest_id, test_title, test_contents, test_date.test_imageのデータがid毎に全部入っています
何を使ってどうすればいいかわかりません、誰かが助けてください!!
index.htmlの一覧ページがありますその中に<a href="100.html"></a>あるとします、これの飛ぶ先の100.htmlファイルを書き出したいです
ユーザー側が観れる、index.html一覧ページ:
<div><a href="100.html"></a></div> <div><a href="99.html"></a></div> <div><a href="98.html"></a></div> <div><a href="97.html"></a></div> <div><a href="96.html"></a></div>
これは管理画面ですべての記事ページを作っています。
管理画面のview.phpです:
<form action="" method='post'> <table> <thead> <tr> <th>ID</th> <th>タイトル</th> <th>商品名</th> <th>作者</th> <th>項目名</th> <th>画像</th> <th>日付</th> <th>内容</th> <th>xxx</th> <th>編集</th> <th>削除</th> <th>STG同期</th> </tr> </thead> <tbody> <?php require_once("db.php"); $query = "SELECT * FROM test ORDER BY test_id DESC"; $select = mysqli_query($db, $query); while($row = mysqli_fetch_assoc($select)){ $test_id =$row['test_id']; $test_title = $row['test_title']; $test_product =$row['test_product']; $test_author =$row['test_author']; $test_koumoku =$row['test_koumoku']; $test_date = $row['test_date']; $test_hunbun = $row['test_hunbun']; echo "<tr>"; ?> <?php echo "<td>$test_id</td>"; echo "<td>$test_title</td>"; echo "<td>$test_product</td>"; echo "<td>$test_author</td>"; echo "<td>$test_koumoku</td>"; echo "<td>$test_image</td>"; echo "<td>$test_date</td>"; echo "<td>$test_hunbun</td>"; echo "<td><a href=''>xxx</td>"; echo "<td><a href=''>編集</td>"; echo "<td><a href=''>削除</td>"; //ここまで考えたのですが次はどうすればいいかわかりません、下記のstg同期ボタンを押したらid.htmlとして書き出したいです。 //sync.phpを作ればいいかと思いましたが書方がわかりません。例:100.htmlにてここにあるすべての項目がhtml式で書き出せるようにしたいです。 echo "<td><form action='sync.php' method='post'><div> <input type='submit' class='btn' name='$test_id' value='stg同期'></div></form></td>"; echo "</tr>"; } ?></tbody> </table> </form>
こちらがsync.phpですが問題はidごとに書き出したいので、ここはダメかなと
<?php if(isset($_GET['test_id'])){ $the_id = $_GET['test_id']; } $query = "SELECT * FROM test WHERE test_id = $the_id"; $select_query = mysqli_query($db, $query); while($row = mysqli_fetch_assoc($select_query)){ $test_id =$row['test_id']; $test_title = $row['test_title']; $test_product =$row['test_product']; $test_author =$row['test_author']; $test_koumoku =$row['test_koumoku']; $test_date = $row['test_date']; $test_hunbun = $row['test_hunbun']; ?> <p><?php echo $special_planning; ?><br> <p><?php echo $special_title; ?></p> <?php } ?> <?php $url = "http://superceo.local/test/sync.php"; $buff = file_get_contents($url); //ここをどうしたらいいですか?後stg同期を押した時に実行されません $fname ="/Applications/MAMP/htdocs/stg/test/ここに入るID.html"; $fhandle = fopen($fname, "w"); fwrite($fhandle, $buff); fclose($fhandle); ?>
回答2件
あなたの回答
tips
プレビュー