PHP开发企业网站教程之展示新闻资讯(一)

前面的内容我们已经介绍了如何展示信息了,看代码:

<?php
    require_once('conn.php'); //连接数据库
    require_once('functions.php');
    $sql = "SELECT * FROM news order by id desc";
    $info = mysql_query($sql);    
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>展示新闻资讯</title>
    <style type="text/css">
        .top{height:30px;line-height:30px;float:right;margin-right:15px;}
        .top a{color:red;text-decoration:none;}
        .cont{width:100%;height:300px;float:left;}
        .cont_ct{float:left;}
        table{width:100%;border:1px solid #eee;text-align:center;}
        th{background:#eee;}
        td{width:200px;height:30px;}
    </style>
</head>
<body>
    <div class="top"><a href="addne.php">添加新闻资讯</a></div>

    <div class="cont">
        <table cellspacing="0" cellpadding="0" border="1">
            <tr>
                <th>ID</th>
                <th>类别</th>
                <th>标题</th>
                <th>内容</th>
                <th>操作</th>
            </tr>
            <?php
                //获取表中的数据
                while($row=mysql_fetch_array($info)){
            ?>
            <tr>
                <td><?php echo $row['id'];?></td>
                <?php
                    if($row['type']==1){
                ?>
                <td>公司新闻</td>
                <?php
                    }else{
                ?>
                <td>公司公告</td>
                <?php
                    }
                ?>
                <td><?php echo $row['title'];?></td>
                <td><?php echo msubstr($row['content'],0,15);?></td>
                <td>
                    <a href="modifnew.php?id=<?php echo $row['id'];?>">修改</a>
                    <a href="delnews.php?id=<?php echo $row['id'];?>">删除</a>
                </td>
            </tr>
            <?php
                }
            ?>
        </table>
    </div>
</body>
</html>

如上代码就已经把新闻的信息展示出来了

继续学习
||
<?php require_once('conn.php'); //连接数据库 require_once('functions.php'); $sql = "SELECT * FROM news order by id desc"; $info = mysql_query($sql); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>展示新闻资讯</title> <style type="text/css"> .top{height:30px;line-height:30px;float:right;margin-right:15px;} .top a{color:red;text-decoration:none;} .cont{width:100%;height:300px;float:left;} .cont_ct{float:left;} table{width:100%;border:1px solid #eee;text-align:center;} th{background:#eee;} td{width:200px;height:30px;} </style> </head> <body> <div class="top"><a href="addne.php">添加新闻资讯</a></div> <div class="cont"> <table cellspacing="0" cellpadding="0" border="1"> <tr> <th>ID</th> <th>类别</th> <th>标题</th> <th>内容</th> <th>操作</th> </tr> <?php //获取表中的数据 while($row=mysql_fetch_array($info)){ ?> <tr> <td><?php echo $row['id'];?></td> <?php if($row['type']==1){ ?> <td>公司新闻</td> <?php }else{ ?> <td>公司公告</td> <?php } ?> <td><?php echo $row['title'];?></td> <td><?php echo msubstr($row['content'],0,15);?></td> <td> <a href="modifnew.php?id=<?php echo $row['id'];?>">修改</a> <a href="delnews.php?id=<?php echo $row['id'];?>">删除</a> </td> </tr> <?php } ?> </table> </div> </body> </html>
提交重置代码
章节
笔记
提问
课件
反馈
捐赠

PHP开发企业网站实战教程

  • 推荐课程
  • 评论
  • 问答
  • 笔记
  • 课件下载

conn.php和functions.php两个文件的代码在哪里?

[最新 phpcn_u83868 的回答] 以上是conn.php的内容 functions.php 不知道是什么内容 刚开始学习 还没弄明白 这个文件要实现什么作用

时间:7年前

求指教一下嘿嘿

[最新 电动小老虎 的回答] 只引入一次  conn.php 这个 文件     require  引入 如果文件有问题 就会停止运行,include 引入不会影响程序运行。

时间:7年前

关于修改和删除的问题?

[最新 数据分析师 的回答] 关于修改和删除的问题?-PHP中文网问答-关于修改和删除的问题?-PHP中文网问答围观一下哦,学习一下。

时间:8年前

课件暂不提供下载,工作人员正在整理中,后期请多关注该课程~