PHP開発掲示板のメッセージを見る
ファイルを作成しますlist.php
<!DOCTYPE html>
<html lang="utf-8">
<head>
<?php
include ("conn.php");
?>
<link href="css.css" rel="stylesheet" type="text/css">
</head>
<table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef" >
<?php
$sql="select * from message order by id desc";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){ ?>
<tr bgcolor="#eff3ff">
<td>标题: <?php echo $row['title'];?> <font color="red">用户: <?php echo $row['user'];?> </td>
</tr>
<tr bgColor="#ffffff">
<td>发表内容:<?php echo $row['content'];?></td>
</tr>
<tr bgColor="#ffffff">
<td><div align="right">时间:<?php echo $row['lastdate'];?></td>
</tr>
<?php } ?>
<tr bgcolor="#f0fff0">
<td><div align="right"><a href="add.html">返回留言</a> </td>
</tr>
</table>
</html>CSSスタイルファイルとconnデータベースファイルを導入します
<?php
$sql="select * from message order by id desc";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){
} ?>接続メッセージデータベースは逆方向にソートされています
mysql_queryQuery
mysql_fetch_array() - データ形式を取得して表示します
その後、必要なデータを別途書き出します
この掲示板を書いた後、基本的に形になりました メッセージに削除関数を追加できます。後でボードに貼り付けると、より完全になります。
この章の焦点:
HTML と PHP を組み合わせた HTML ステートメントに php ステートメントを挿入します。
フラッシュバックを使用してデータを表示します。最新のデータが一番上に表示されるため、ユーザーの使用習慣により一致します。
mysql_query (クエリ用) と mysql_fetch_array() - これら 2 つのメソッドを使用してデータ形式を取得および表示します。
新しいファイル
<!DOCTYPE html>
<html lang="utf-8">
<head>
<?php
include ("conn.php");
?>
<link href="css.css" rel="stylesheet" type="text/css">
</head>
<table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef" >
<?php
$sql="select * from message order by id desc";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){ ?>
<tr bgcolor="#eff3ff">
<td>标题: <?php echo $row['title'];?> <font color="red">用户: <?php echo $row['user'];?> </td>
</tr>
<tr bgColor="#ffffff">
<td>发表内容:<?php echo $row['content'];?></td>
</tr>
<tr bgColor="#ffffff">
<td><div align="right">时间:<?php echo $row['lastdate'];?></td>
</tr>
<?php } ?>
<tr bgcolor="#f0fff0">
<td><div align="right">< a href=" ">返回留言</ a> </td>
</tr>
</table>
</html>
プレビュー
Clear
- おすすめコース
- コースウェアのダウンロード
現時点ではコースウェアはダウンロードできません。現在スタッフが整理中です。今後もこのコースにもっと注目してください〜
このコースを視聴した生徒はこちらも学んでいます
















