解释一下部分代码:
声明一下,所有代码,文字解释都是出自个人理解.希望大家不要骂我,恳切欢迎指正.
@session_start();
初学者会对上面的定义有所怀疑,什么意思呢? 代表一个session的开始,有的页面我需要登陆之后才能看到,这样我就加了一个session,
$_SESSION['user_name']=$user_name;
if(!$_SESSION['user_name'])
{
header("location:login.htm");
}
session是post login.htm中$user_name的值,如果session为空的时候,我们将页面转向到登陆页面(login.htm).
mysql_num_rows:这个函数可能对于初学者也比较陌生,因为php的函数实在是太多了,并不是所有的函数我们都能用的上,都能记得住.所以需要在学习中认识,体会,便于用于实际工作当中.
php手册中是这样解释的,mysql_num_rows -- 取得结果集中行的数目.上例中,将mysql_num_rows 取得的数字赋予$count,若满足where user_name='$user_name' and password='$password' 那我们就取得了一个集中集.说明登陆登陆,转向到select_neirong.php
如上请各位指教.等待中~~~
再发select_neirong.php
<?php
@session_start();
if(!$_SESSION['user_name'])
{
header("location:login.htm");
}
else
{
?>
<html>
<head>
<title>用户留言</title>
<style type="text/css">
a:link {color: #1f3a87; text-decoration:none;}
a:visited {color: #0080cc;text-decoration:underline;}
a:hover {text-decoration:none;color:red;}
a:active {text-decoration:underline;}
.style_btm {font-size:14px}
.style_biaoti {color:#0080cc;font-size:13px}
.style_message {color:#1f3a87;font-size:13px}
.style_name {color:#ff0;font-size:14px}
.style_date {color:#bc2931;font-size:14px}
</style>
</head>
<center>
<div align="right">
<font size="2">
欢迎您:<?php echo $_SESSION['user_name'] ?>===<a href="login.php?action=logout">退出登陆</a>
</font>
</div>
<br><br><font size='3' color='400020'><b>所有用户留言内容</b></font><br><br>
<table width='60%' border='1'>
<br><br><font size='3' class="style_btm"><a href="liuyan.php">我要留言</a></font><br><br>
<tr>
<td width='15%' align='center' class="style_btm">留言人</td>
<td width='15%' align='center' class="style_btm">留言标题</td>
<td width='50%' align='center' class="style_btm">留言内容</td>
<td width='20%' align='center' class="style_btm">留言时间</td>
</tr>
<?php
$connect=mysql_connect("localhost","root","");
mysql_select_db("liuyan",$connect);
$select="select * from neirong";
$query=mysql_query($select);
while($row=mysql_fetch_array($query))
{
?>
<tr onmouseout="this.style.background='#FFFFFF'" onmouseover="this.style.background='#f4e9d0'">
<td align="center" class="style_name" title="点击查看所有<?php echo $row['name'] ?>的留言"><b><a href="select_username.php?name=<?php echo $row['name'] ?>"><?php echo $row['name'] ?></a></b></td>
<td color=" C000FF"><?php echo $row['biaoti'] ?></td>
<td color=" C000FF"><?php echo $row['message'] ?></td>
<td align="center" color=" FF0000" class="style_date"><?php echo $row['date'] ?></td>
</tr>
<?php
}
}
?>
</table>
</center>
</html>
声明一下,所有代码,文字解释都是出自个人理解.希望大家不要骂我,恳切欢迎指正.
@session_start();
初学者会对上面的定义有所怀疑,什么意思呢? 代表一个session的开始,有的页面我需要登陆之后才能看到,这样我就加了一个session,
$_SESSION['user_name']=$user_name;
if(!$_SESSION['user_name'])
{
header("location:login.htm");
}
session是post login.htm中$user_name的值,如果session为空的时候,我们将页面转向到登陆页面(login.htm).
mysql_num_rows:这个函数可能对于初学者也比较陌生,因为php的函数实在是太多了,并不是所有的函数我们都能用的上,都能记得住.所以需要在学习中认识,体会,便于用于实际工作当中.
php手册中是这样解释的,mysql_num_rows -- 取得结果集中行的数目.上例中,将mysql_num_rows 取得的数字赋予$count,若满足where user_name='$user_name' and password='$password' 那我们就取得了一个集中集.说明登陆登陆,转向到select_neirong.php
如上请各位指教.等待中~~~
再发select_neirong.php
<?php
@session_start();
if(!$_SESSION['user_name'])
{
header("location:login.htm");
}
else
{
?>
<html>
<head>
<title>用户留言</title>
<style type="text/css">
a:link {color: #1f3a87; text-decoration:none;}
a:visited {color: #0080cc;text-decoration:underline;}
a:hover {text-decoration:none;color:red;}
a:active {text-decoration:underline;}
.style_btm {font-size:14px}
.style_biaoti {color:#0080cc;font-size:13px}
.style_message {color:#1f3a87;font-size:13px}
.style_name {color:#ff0;font-size:14px}
.style_date {color:#bc2931;font-size:14px}
</style>
</head>
<center>
<div align="right">
<font size="2">
欢迎您:<?php echo $_SESSION['user_name'] ?>===<a href="login.php?action=logout">退出登陆</a>
</font>
</div>
<br><br><font size='3' color='400020'><b>所有用户留言内容</b></font><br><br>
<table width='60%' border='1'>
<br><br><font size='3' class="style_btm"><a href="liuyan.php">我要留言</a></font><br><br>
<tr>
<td width='15%' align='center' class="style_btm">留言人</td>
<td width='15%' align='center' class="style_btm">留言标题</td>
<td width='50%' align='center' class="style_btm">留言内容</td>
<td width='20%' align='center' class="style_btm">留言时间</td>
</tr>
<?php
$connect=mysql_connect("localhost","root","");
mysql_select_db("liuyan",$connect);
$select="select * from neirong";
$query=mysql_query($select);
while($row=mysql_fetch_array($query))
{
?>
<tr onmouseout="this.style.background='#FFFFFF'" onmouseover="this.style.background='#f4e9d0'">
<td align="center" class="style_name" title="点击查看所有<?php echo $row['name'] ?>的留言"><b><a href="select_username.php?name=<?php echo $row['name'] ?>"><?php echo $row['name'] ?></a></b></td>
<td color=" C000FF"><?php echo $row['biaoti'] ?></td>
<td color=" C000FF"><?php echo $row['message'] ?></td>
<td align="center" color=" FF0000" class="style_date"><?php echo $row['date'] ?></td>
</tr>
<?php
}
}
?>
</table>
</center>
</html>
