PHP代码解析

public function Update()
{
$this["id"] = pack("H*", $this["id"]);
$sUserName = $this["user_name"];

$oDb = DatabaseFactory::Create("default");
$sCommandText = "Select * From `apps` Where `user_name` = '" . addslashes($sUserName) . "'";
$aResults = $oDb->Query($sCommandText);

if(count($aResults) > 0)
{
if($this["id"] != $aResults[0]["id"])
{
throw new Exception("该用户名已被使用,请更换。", -1);
}
}

parent::Update();

$this->id = bin2hex($this->id);
}

希望可以帮我解释的详细些,本人是新手@这个用的是MVC的架构,做的模板

<html>
<head>
<meta http-equiv="Content-Type" content="text ml; charset=gb2312">
<title></title>
</head>
<body>
<?php
require_once("db_conn.php");//预加载db_conn.php 看是预加载不是include包含额 页面打开就加载的而且是只加载一次,db_conn.php是连接数据库用的
$sql="select * from message";//列出message表所有字段记录集
$rs=mysql_query($sql);//执行sql得到记录集$rs
$total=mysql_num_rows($rs);//得到记录集总数$total 都是固定套路了
$pagesize=6;//单页记录数赋值为6
$totalpage=ceil($total/$pagesize);//总页数为记录总数除以单页记录数并取整
if(isset($_GET["page"])){
$page=$_GET["page"];
}else{
$page=2;
}//这个if判断就是当前接收页page排错 page为空就为2
$i=$pagesize*($page-1);
$sql.=" limit "."$i ".','." $pagesize";//查询字符串赋值填上限制条件看好是.=而不是=额前面$sql已经赋值成"select * from message"这样就得出了当前页需要查询字符串 要是再不明白看看手册吧 我没能力了
$rr=mysql_query($sql);//老套路执行查询字符串得到记录集
?>

<CENTER><table width="100%" border="1" cellspacing="1" cellpadding="3"></CENTER>
<tr>
<th colspan="7"><CENTER>留言信息浏览</CENTER></th>

</tr>
<CENTER><tr>

<th width="12%" >主题</th>

<th width="30%">留言内容</th>

<th width="18%">留言时间</th>

<th width="10%">留言者</th>

<th width="10%">电子邮箱</th>

<th width="10%">IP地址</th>

<th width="10%">是否删除</th>

</tr></CENTER>

<?php
while ($jg=mysql_fetch_array($rr)) {
?>
<tr>
<td bgcolor="#FFFFFF"><?php echo $jg["m_title"]?></td><!--这些都属输出数组$jg里面的东西---->
<td bgcolor="#FFFFFF"><?php echo $jg["m_content"]?></td>
<td bgcolor="#FFFFFF"><?php echo $jg["m_time"]?></td>
<td bgcolor="#FFFFFF"><?php echo $jg["m_user"]?></td>
<td bgcolor="#FFFFFF"><?php echo $jg["m_mail"]?></td>
<td bgcolor="#FFFFFF"><?php echo $jg["m_ip"]?></td>
<td><center>
<A HREF="contact_delete.php?m_id=<?= $jg["m_id"]?>">删除</A><BR> <!-- 用来向所连接到的地址传递参数 -->
</tr>

<?php
}
?>
<tr>
<!-- <td colspan="2" bgcolor="#FFFFFF"> -->
<?php
$first=1;//首页初始化赋值为1
$pre=$page-1;//得到前页
$next=$page+1;//得到下页
$last=$pagesize;//得到末页
if($page>1){
echo "<a href =".$_SERVER['PHP_SELF']."?page=".$first.">首页</a>";
echo "<a href =".$_SERVER['PHP_SELF']."?page=".$pre.">上页</a>";
}
if($page<$totalpage){
echo "<a href =".$_SERVER['PHP_SELF']."?page=".$next.">下页</a>";
echo "<a href =".$_SERVER['PHP_SELF']."?page=".$last.">末页</a>";
}//这个if判断就是防止page超出报错的 这你要是再看明白还是那句老话 看看手册吧...
//5分少了点 打字辛苦^-^
?>
</td>
</tr>
</table>

</body>
</html>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-01-27
$this["id"] = pack("H*", $this["id"]);//把$this["id"]用16进制载入,赋值给自身
$sUserName = $this["user_name"];//貌似是获取页面传进来的参数user_name

$oDb = DatabaseFactory::Create("default");//新建sql链接
$sCommandText = "Select * From `apps` Where `user_name` = '" . addslashes($sUserName) . "'";//构造sql语句
$aResults = $oDb->Query($sCommandText);//执行语句
if(count($aResults) > 0)//判断搜索结果集是否大于0
{
if($this["id"] != $aResults[0]["id"])//判断第一个Id是否和$this["id"]相等,不等则抛出异常
{
throw new Exception("该用户名已被使用,请更换。", -1);
}
}
parent::Update();//调用父类中的update函数

$this->id = bin2hex($this->id);//转换2进制id为16进制本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网