相关关键词
关于我们
最新文章
使用PHP连接数据库_实现用户数据的增删改查的整体操作示例
发布日期:2017-09-01 00:00:00
75
main页面(主页面)
<table width="100%" border="1" cellpadding="0" cellspacing="0"> <tr> <td>代号</td> <td>姓名</td> <td>性别</td> <td>民族</td> <td>生日</td> <td>操作</td> </tr> <?php $db = new MySQLi("localhost","root","","mydb"); if(mysqli_connect_error()){ die("连接失败"); } $sql = "select * from Info"; $result = $db->query($sql); $attr = $result->fetch_all(); foreach($attr as $v) { $sex = $v[2]? '男':'女'; //三元运算符判断性别 $sql = "select Name from Nation where Code ='$v[3]'"; $result = $db ->query($sql); $attr = $result->fetch_assoc(); echo "<tr> <td>{$v[0]}</td> <td>{$v[1]}</td> <td>{$sex}</td> <td>{$attr['Name']}</td> <td>{$v[4]}</td> <td> <a href='Delete.php?code={$v[0]}'>删除</a> <a href='Update.php?code={$v[0]}'>修改</a> </td> </tr>"; } ?> </table> <div> <a href="Add.php" rel="external nofollow" >添加数据</a> </div>