PHP练习之简单好友列表操作
经过几天的学习,实现了一个简单粗糙的通过连接数据库从而实现查询、添加、删除好友,设置备注名称的页面,其中只做了查询功能,增删改没做,大体效果上图(丑的一B):
代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>好友界面</title> </head> <body> <h1 align="center">好友列表</h1> <?php include ("database.class.php"); $wx= new database(); $search=""; $value=""; if(!empty($_POST["name"])) { $name=$_POST["name"]; $search=" where Name like '{$name}%'"; $value=$name; } ?> <table width="100%" cellpadding="0" cellspacing="0" border="1"> <tr> <td>代号</td> <td>姓名</td> <td>性别</td> <td>手机</td> <td>头像</td> <td>管理员操作</td> </tr> <?php //$sql="select * from wxfriend".$search; $result=$wx->query("select * from wxfriend".$search); foreach($result as $v) { $key="<span style='color:red'>$value</span>"; $str =str_replace($value,$key,$v[1]); echo "<tr> <td>{$v[0]}</td> <td>{$str}</td> <td>{$v[2]}</td> <td>{$v[3]}</td> <td>{$v[4]}</td> <td><a href='deletefriend.php'>删除好友</a> <a href='updatefriend.php'>设置备注</a></td> </tr>"; } ?> </table> <br /> <div><form action="test-5-6-exercise.php" method="post"> 查询好友:<input type="text" name="name" value="<?php echo $value; ?>" /> <input type="submit" value="查询" /> </form> <br /> </div> <div style="float:left"><a href="addfriend.php"><h2>添加好友</h2></a></div> <div style="float:right"><a href="test-5-6-exercise.php"><h2>返回首页</h2></a></div> </body> </html>