博客列表 >12月10日php大作业

12月10日php大作业

随风
随风原创
2019年12月20日 15:41:171253浏览

架构上传


部分源码上传

model

`<?php
namespace model;
use PDO;

//数据连接,数据查询

class Db
{
//数据库连接
private $dsn;
private $user;
private $password;
private $pdo;

  1. public function connect()
  2. {
  3. try {
  4. $this->pdo = new PDO($this->dsn, $this->user, $this->password);
  5. } catch (PDOException $e) {
  6. die('数据库连接失败,错误信息:' . $e->getMessage());
  7. }
  8. }
  9. public function __construct($dsn = 'mysql:host=localhost;dbname=phpdzy', $user = 'root', $password = 'root')
  10. {

// $this->pdo = new PDO($dsn,$user,$password);
$this->dsn = $dsn;
$this->user = $user;
$this->password = $password;
$this->connect();

  1. }
  2. //获取用户全部信息
  3. public function seleUsers()
  4. {
  5. $sql = 'SELECT * FROM `category`';
  6. $stmt = $this->pdo->prepare($sql);
  7. $stmt->execute();
  8. return $stmt->fetchAll(PDO::FETCH_ASSOC);
  9. }
  10. // 查询多条记function select($table,$fields='*',$where='',$order='',$limit='// 创建SQL语句

// 查询多条记录
function select($table ,$where = ‘’, $limit = ‘’, $fields = ‘*’, $order = ‘’)
{
// 创建SQL语句
$sql = ‘SELECT ‘;
if (is_array($fields)) {
foreach ($fields as $field) {
$sql .= $field . ‘, ‘;
}
} else {
$sql .= $fields;
}
$sql = rtrim(trim($sql), ‘,’);
$sql .= ‘ FROM ‘ . $table;
// 查询条件
if (!empty($where)) {
$sql .= ‘ WHERE ‘ . $where;
}
// 排序方式
if (!empty($order)) {
$sql .= ‘ ORDER BY ‘ . $order;
}
// 分页
if (!empty($limit)) {
$sql .= ‘ LIMIT ‘ . $limit;
}
$sql .= ‘;’;
// 创建PDO预处理对象
$stmt = $this->pdo->prepare($sql);
// 执行查询操作
if ($stmt->execute()) {
if ($stmt->rowCount() > 0) {
$stmt->setFetchMode(PDO::FETCH_ASSOC);
return $stmt->fetchAll();
}
}
return ‘查询失败’;
}

  1. // 查询单条记录
  2. function find($table,$fields,$where=''){
  3. $sql = 'SELECT ';
  4. if(is_array($fields)){
  5. foreach ($fields as $field){
  6. $sql .= $field . ', ';
  7. }
  8. }else{
  9. $sql .= $fields;
  10. }
  11. $sql = rtrim(trim($sql),',');
  12. $sql .= ' FROM ' . $table;
  13. if(!empty($where)){
  14. $sql .= ' WHERE ' . $where;
  15. }
  16. $sql .= ' LIMIT 1;';
  17. $stmt = $this->pdo->prepare($sql);

// print_r($stmt);
if($stmt->execute()){
if ($stmt->rowCount()>0){
$stmt->setFetchMode(PDO::FETCH_ASSOC);
return $stmt->fetch();
}
}
return ‘查询失败’;
}

}
//
// $db = new Db();
//print_r($db->seleUsers());
//$data =$db->select(‘users’);
////print_r($data);
//查询多条记录
// echo ‘<pre>‘ .print_r($db->select(‘article’),true);

// 查询单条记录

//echo ‘<pre>‘ .print_r($db->find(‘users’,’*’,’user = “gzg”‘ ),true);

//$data =new Db();
//$data1=$data->find(‘users’,’*’,’user=”gzg”‘);
//print_r($data1);

`

控制

`<?php
namespace ph;
use model\Db;
use view\View1;
require DIR . ‘/Model/model.php’;
require DIR . ‘/View/View.php’;

class indexConter
{

  1. public function article($table,$where,$limit)
  2. {
  3. $art = new Db();
  4. $art1 =$art->select($table,$where,$limit);

// print_r($art1);

  1. $view =new View1;
  2. return $view->getData($art1);
  3. }
  4. public function category($table,$where,$limit)
  5. {
  6. $cat =new Db();
  7. $cat =$cat->select($table,$where,$limit);
  8. $view =new View1;
  9. return $view->getData($cat);
  10. }

}
$index =new indexConter();
//$index =new indexConter();
// $res=$index->article(‘article’);
// print_r($res);

//$art = new Db();
//$art1 =$art->select(‘article’);
//print_r($art1);
//exit();`

index

`<?php

use ph\indexConter;
require DIR . ‘/head.php’;
require DIR .’./../indexConter.php’;

//$limit1=$index->article(‘article’,’1’);
$limit9=$index->article(‘article’,’cate_id=1’,’9’);
$limit92=$index->article(‘article’,’cate_id=2’,’9’);
// print_r($limit9);
$cat =$index->category(‘category’,’cate_id=1’,’1’);
$cat1 =$index->category(‘category’,’cate_id=2’,’1’);
$pic =$index->article(‘image’,’’,’’);
$pic_con =$index->article(‘image_conten’,’image_id=1’,’2’);
$pic_con_2 =$index->article(‘image_conten’,’image_id=1’,’2,2’);
$phop = $index->article(‘phop’,’’,’’);
$phop_con = $index->article(‘phop_conten’,’phop_id=1’,’4’);
$phop_con_4 = $index->article(‘phop_conten’,’phop_id=1’,’4,4’);
//print_r($phop);
//print_r($phop_con);
//$id=$pic[‘image_id’];
//print_r($id);
//exit;

//print_r($pic_con_2);
//class article1
//{
//
// public function arct1($art1)
// {
//
// foreach ($art1 as $v) {
// // echo $v[‘title’];
// echo ‘<li><span>[新闻]</span><a href=""> ‘;
// echo $v[‘title’];
// echo ‘<br>‘;
// echo ‘</a></li>‘;
// }
//
// }
//
//
//
//}

//echo ‘1110’;
// $data = new article1( );
// print_r($data->arct1($art1));
//print_r($data);
?>

<!--新闻资讯区-->

<div class="news">
<div class="title">
<a>新闻资讯</a>
<a href="">更多</a>
</div>

  1. <div class="content">
  2. <div class="pic">
  3. <a href=""><img src="/phpdzy/static/images/news.jpg" alt="" class="first-img"></a>
  4. <a href=""><img src="/phpdzy/static/images/n-2.jpg" alt=""></a>
  5. <a href=""><img src="/phpdzy/static/images/n-3.jpg" alt=""></a>
  6. <a href="">三星Note10/10+发布 <br> 搭载挖孔前摄</a>
  7. <a href="">小米公布6400万 <br> 和1亿像素手机信息</a>
  8. </div>
  9. <div class="list">
  10. <?php foreach ($cat as $c) : ?>

<!-- mb_substr($row['title'],0,15 ) 取前15个字段 -->

  1. <a href="article_list.php?id=<?php echo $c['cate_id'] ?>"><?php echo mb_substr($c['name'],0,15 )?></a>
  2. <?php endforeach;?>
  3. <ul><?php foreach ($limit9 as $row9) : ?>
  4. <li><span>[新闻]</span><a href="article.php?id=<?php echo $row9['article_id'] ?>"><?php echo $row9['title'] ?></a></li>
  5. <?php endforeach;?>

<!-- <li><span>[新闻]</span><a href="">佳能注册相机无线充电和眼控对焦专利</a></li>-->

<!-- <li><span>[新闻]</span><a href="">Entaniya宣布推出Super 35 PL卡口鱼眼镜头</a></li>-->

<!-- <li><span>[新闻]</span><a href="">轻便灵巧可变形 JOBY入门迷你三脚架套装试用</a></li>-->

<!-- <li><span>[新闻]</span><a href="">乐摄宝Photo Active BP 300 AW背包评测</a></li>-->

<!-- <li><span>[新闻]</span><a href="">佳能注册相机无线充电和眼控对焦专利</a></li>-->

<!-- <li><span>[新闻]</span><a href="">Entaniya宣布推出Super 35 PL卡口鱼眼镜头</a></li>-->

<!-- <li><span>[新闻]</span><a href="">轻便灵巧可变形 JOBY入门迷你三脚架套装试用</a></li>-->

<!-- <li><span>[新闻]</span><a href="">乐摄宝Photo Active BP 300 AW背包评测</a></li>-->

<!-- <li><span>[新闻]</span><a href="">乐摄宝Photo Active BP 300 AW背包评测</a></li>-->

  1. </ul>
  2. </div>
  3. <div class="list">
  4. <?php foreach ($cat1 as $row1) : ?>

<!-- <a href="">性价比广角 腾龙17-28F2.8评测</a>-->

  1. <a href="article_list.php?id=<?php echo $row1['cate_id'] ?>"><?php echo mb_substr($row1['name'],0,15) ?></a>
  2. <?php endforeach;?>
  3. <ul>
  4. <?php foreach ($limit92 as $row9) : ?>
  5. <li><span>[新闻]</span><a href="article.php?id=<?php echo $row9['article_id'] ?>"><?php echo $row9['title'] ?></a>
  6. <?php endforeach; ?>

<!-- <li><span>[新闻]</span><a href="">佳能注册相机无线充电和眼控对焦专利</a></li>-->

<!-- <li><span>[新闻]</span><a href="">Entaniya宣布推出Super 35 PL卡口鱼眼镜头</a></li>-->

<!-- <li><span>[新闻]</span><a href="">轻便灵巧可变形 JOBY入门迷你三脚架套装试用</a></li>-->

<!-- <li><span>[新闻]</span><a href="">乐摄宝Photo Active BP 300 AW背包评测</a></li>-->

<!-- <li><span>[新闻]</span><a href="">佳能注册相机无线充电和眼控对焦专利</a></li>-->

<!-- <li><span>[新闻]</span><a href="">Entaniya宣布推出Super 35 PL卡口鱼眼镜头</a></li>-->

<!-- <li><span>[新闻]</span><a href="">轻便灵巧可变形 JOBY入门迷你三脚架套装试用</a></li>-->

<!-- <li><span>[新闻]</span><a href="">乐摄宝Photo Active BP 300 AW背包评测</a></li>-->

<!-- <li><span>[新闻]</span><a href="">乐摄宝Photo Active BP 300 AW背包评测</a></li>-->

  1. </ul>
  2. </div>
  3. </div>

</div>

<!--图片专区-->

<div class="title">
<span>图片专区</span>
</div>
<div class="picture">
<?php foreach ($pic as $p) :?>
<div>

<div>

<a href="image.php?id=<?php echo $p['image_id'] ?>"><?php echo $p[‘name’] ?></a>
<span>纵观摄影艺术</span>
</div>

  1. <?php foreach ($pic_con as $pi ): ?>
  2. <a href="image-content.php?id=<?php echo $pi['image_con_id'] ?> "><img src="<?php echo $pi['dz'] ?>" alt="" width="162" height="122"></a>
  3. <?php endforeach; ?>
  4. <?php foreach ($pic_con as $pi ): ?>
  5. <a href="image-content.php?id=<?php echo $pi['image_con_id'] ?>"><span><?php echo $pi['title'] ?></span></a>
  6. <?php endforeach; ?>
  7. <?php foreach ($pic_con_2 as $pi ): ?>
  8. <a href="image-content.php?id=<?php echo $pi['image_con_id'] ?>"><img src="<?php echo $pi['dz'] ?>" alt="" width="162" height="122"></a>
  9. <?php endforeach; ?>
  10. <?php foreach ($pic_con_2 as $pi ): ?>
  11. <a href="image-content.php?id=<?php echo $pi['image_con_id'] ?>"><span><?php echo $pi['title'] ?></span></a>
  12. <?php endforeach; ?>

<!-- <a href=""><img src="/phpdzy/static/images/img1.jpg" alt="" width="162" height="122"></a>-->

<!-- <a href=""><img src="/phpdzy/static/images/img2.jpg" alt="" width="162" height="122"></a>-->

<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->

<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->

<!-- <a href=""><img src="/phpdzy/static/images/img3.jpg" alt="" width="162" height="122"></a>-->

<!-- <a href=""><img src="/phpdzy/static/images/img4.jpg" alt="" width="162" height="122"></a>-->

<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->

<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->

  1. </div>
  2. <?php endforeach; ?>

<!-- <div>-->

<!-- <div>-->

<!-- <a href="">美女</a>-->

<!-- <span>纵观摄影艺术</span>-->

<!-- </div>-->

<!-- <a href=""><img src="/phpdzy/static/images/img5.jpg" alt="" width="162" height="122"></a>-->

<!-- <a href=""><img src="/phpdzy/static/images/img6.jpg" alt="" width="162" height="122"></a>-->

<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->

<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->

<!-- <a href=""><img src="/phpdzy/static/images/img7.jpg" alt="" width="162" height="122"></a>-->

<!-- <a href=""><img src="/phpdzy/static/images/img8.jpg" alt="" width="162" height="122"></a>-->

<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->

<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->

<!-- </div>-->

<!---->

<!-- <div>-->

<!-- <div>-->

<!-- <a href="">美女</a>-->

<!-- <span>纵观摄影艺术</span>-->

<!-- </div>-->

<!-- <a href=""><img src="/phpdzy/static/images/img1.jpg" alt="" width="162" height="122"></a>-->

<!-- <a href=""><img src="/phpdzy/static/images/img2.jpg" alt="" width="162" height="122"></a>-->

<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->

<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->

<!-- <a href=""><img src="/phpdzy/static/images/img3.jpg" alt="" width="162" height="122"></a>-->

<!-- <a href=""><img src="/phpdzy/static/images/img4.jpg" alt="" width="162" height="122"></a>-->

<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->

<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->

<!-- </div>-->

</div>

<!--二手交易专区-->

<div class="title">
<span>二手交易</span>
</div>

<div class="second-hand">
<div>
<a href="">抢好货</a>
<span>0低价, 便捷,安全,快速</span>
</div>
<div>
<span>热门分类</span>
<?php foreach ($phop as $p) : ?>
<a href="shop.php?id=<?php echo $p['phop_id'] ?>"><?php echo $p[‘name’] ?></a>

<?php endforeach; ?>
<!-- <a href="">美女写真</a>-->
<!-- <a href="">日本美女</a>-->
<!-- <a href="">美国美女</a>-->
<!-- <a href="">国内美女</a>-->
<!-- <a href="">AV美女</a>-->
</div>

  1. <?php foreach ($phop_con as $ph) : ?>
  2. <a href="shop-content.php?id=<?php echo $ph['id'] ?>"><img src="<?php echo $ph['tp'] ?>" alt="" width="176" height="120"></a>
  3. <?php endforeach; ?>

<!-- <a href=""><img src="/phpdzy/static/images/shop/shop1.jpg" alt="" width="176" height="120"></a>-->

<!-- <a href=""><img src="/phpdzy/static/images/shop/shop2.jpg" alt="" width="176" height="120"></a>-->

<!-- <a href=""><img src="/phpdzy/static/images/shop/shop3.jpg" alt="" width="176" height="120"></a>-->

<!-- <a href=""><img src="/phpdzy/static/images/shop/shop4.jpg" alt="" width="176" height="120"></a>-->

<?php foreach ($phop_con as $ph) : ?>
<div class="detail">
<a href="shop-content.php?id=<?php echo $ph['id'] ?>"><?php echo $ph[‘title’] ?></a>
<div>
<a href="shop-content.php?id=<?php echo $ph['id'] ?>">
<span>¥ <?php echo $ph[‘amnt’]?></span>
<span>美女</span>
</a>
</div>

  1. </div>

<?php endforeach; ?>
<!-- <div class="detail">-->
<!-- <a href="">美女性感写真海报墙面贴画艺术装画</a>-->
<!-- <div>-->
<!-- <a href="">-->
<!-- <span>¥ 333</span>-->
<!-- <span>美女</span>-->
<!-- </a>-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="detail">-->
<!-- <a href="">美女性感写真海饰画酒吧卧室贴画图画</a>-->
<!-- <div>-->
<!-- <a href="">-->
<!-- <span>¥ 333</span>-->
<!-- <span>美女</span>-->
<!-- </a>-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="detail">-->
<!-- <a href="">美女性感写真海饰画酒吧卧室贴画图画</a>-->
<!-- <div>-->
<!-- <a href="">-->
<!-- <span>¥ 333</span>-->
<!-- <span>美女</span>-->
<!-- </a>-->
<!-- </div>-->
<!-- </div>-->
<?php foreach ($phop_con_4 as $ph) : ?>
<a href="shop-content.php?id=<?php echo $ph['id'] ?>"><img src="<?php echo $ph['tp'] ?>" alt="" width="176" height="120"></a>
<?php endforeach; ?>
<!-- <a href=""><img src="/phpdzy/static/images/shop/shop5.jpg" alt="" width="176" height="120"></a>-->
<!-- <a href=""><img src="/phpdzy/static/images/shop/shop6.jpg" alt="" width="176" height="120"></a>-->
<!-- <a href=""><img src="/phpdzy/static/images/shop/shop7.jpg" alt="" width="176" height="120"></a>-->
<!-- <a href=""><img src="/phpdzy/static/images/shop/shop8.jpg" alt="" width="176" height="120"></a>-->
<?php foreach ($phop_con_4 as $ph) : ?>
<div class="detail">
<a href="shop-content.php?id=<?php echo $ph['id'] ?>"><?php echo $ph[‘title’] ?></a>
<div>
<a href="shop-content.php?id=<?php echo $ph['id'] ?>">
<span>¥ <?php echo $ph[‘amnt’]?></span>
<span>美女</span>
</a>
</div>

  1. </div>
  2. <?php endforeach; ?>

<!-- <div class="detail">-->

<!-- <a href="">美女性感写真海报墙艺术装饰画贴画图画</a><br>-->

<!-- <div>-->

<!-- <a href="">-->

<!-- <span>¥ 333</span>-->

<!-- <span>美女</span>-->

<!-- </a>-->

<!-- </div>-->

<!-- </div>-->

<!-- <div class="detail">-->

<!-- <a href="">美女性感写真海报墙面贴画艺术装画</a>-->

<!-- <div>-->

<!-- <a href="">-->

<!-- <span>¥ 333</span>-->

<!-- <span>美女</span>-->

<!-- </a>-->

<!-- </div>-->

<!-- </div>-->

<!-- <div class="detail">-->

<!-- <a href="">美女性感写真海饰画酒吧卧室贴画图画</a>-->

<!-- <div>-->

<!-- <a href="">-->

<!-- <span>¥ 333</span>-->

<!-- <span>美女</span>-->

<!-- </a>-->

<!-- </div>-->

<!-- </div>-->

<!-- <div class="detail">-->

<!-- <a href="">美女性感写真海饰画酒吧卧室贴画图画</a>-->

<!-- <div>-->

<!-- <a href="">-->

<!-- <span>¥ 333</span>-->

<!-- <span>美女</span>-->

<!-- </a>-->

<!-- </div>-->

<!-- </div>-->

  1. <div>
  2. <a href=""><img src="/phpdzy/static/images/ad/1.png" alt="" width="180" height="112"></a>
  3. <a href=""><img src="/phpdzy/static/images/ad/2.png" alt="" width="180" height="112"></a>
  4. <a href=""><img src="/phpdzy/static/images/ad/3.png" alt="" width="180" height="112"></a>
  5. <a href=""><img src="/phpdzy/static/images/ad/4.png" alt="" width="180" height="112"></a>
  6. <a href=""><img src="/phpdzy/static/images/ad/image.png" alt="" width="393" height="56"></a>
  7. <a href=""><img src="/phpdzy/static/images/ad/ad2.jpg" alt="" width="393" height="56"></a>
  8. </div>

</div>

  1. <!--合作网站-->
  2. <div class="title" style="background:#fff">
  3. <span>合作网站</span>
  4. </div>
  5. <div class="my-links">
  6. <a href="https://www.php.cn">php中文网</a>
  7. <a href="https://www.html.cn">html中文网</a>
  8. <a href="https://www.py.cn">python中文网</a>
  9. <a href="https://www.php.cn">php中文网</a>
  10. <a href="https://www.html.cn">html中文网</a>
  11. <a href="https://www.py.cn">python中文网</a>
  12. <a href="https://www.php.cn">php中文网</a>
  13. <a href="https://www.html.cn">html中文网</a>
  14. <a href="https://www.py.cn">python中文网</a>
  15. <a href="https://www.php.cn">php中文网</a>
  16. <a href="https://www.html.cn">html中文网</a>
  17. <a href="https://www.py.cn">python中文网</a>
  18. <a href="https://www.py.cn">python中文网</a>
  19. <a href="https://www.php.cn">php中文网</a>
  20. <a href="https://www.html.cn">html中文网</a>
  21. <a href="https://www.py.cn">python中文网</a>
  22. <a href="https://www.php.cn">php中文网</a>
  23. <a href="https://www.html.cn">html中文网</a>
  24. <a href="https://www.py.cn">python中文网</a>
  25. <a href="https://www.php.cn">php中文网</a>
  26. <a href="https://www.html.cn">html中文网</a>
  27. <a href="https://www.py.cn">python中文网</a>
  28. <a href="https://www.php.cn">php中文网</a>
  29. <a href="https://www.html.cn">html中文网</a>
  30. <a href="https://www.py.cn">python中文网</a>
  31. <a href="https://www.py.cn">python中文网</a>
  32. </div>

<?php
require DIR . ‘/foot.php’;`

新闻列表

` <h3>推荐阅读</h3>
<?php foreach ($tj_4_1 as $tj) : ?>
<a href="article.php?id=<?php echo $tj['article_id'] ?>"><img src="<?php echo $tj['image'] ?>" alt="" width="195" height="130"></a>
<?php endforeach; ?>

  1. <?php foreach ($tj_4_1 as $ti) : ?>
  2. <a href="article.php?id=<?php echo $tj['article_id'] ?>"><?php echo $ti['title'] ?></a>
  3. <?php endforeach; ?>
  4. <?php foreach ($tj_4_2 as $tj) : ?>
  5. <a href="article.php?id=<?php echo $tj['article_id']?>"><img src="<?php echo $tj['image'] ?>" alt="" width="195" height="130"></a>
  6. <?php endforeach; ?>
  7. <?php foreach ($tj_4_2 as $ti) : ?>
  8. <a href="article.php?id=<?php echo $tj['article_id'] ?>"><?php echo $ti['title'] ?></a>
  9. <?php endforeach; ?>`

新闻

<article> <h1><?php echo $res['title'] ?></h1> <div> <span>发布时间:<?php echo $res['fb_date'] ?></span> <span>来源:<?php echo $res['soure'] ?></span> <span>阅读量:<?php echo $res['ydl'] ?></span> <span>评论数:<?php echo $res['pls']?></span> </div> <div> <?php echo $res['detail'] ?> </div> </article>

由于内容较多不再一一上传

截图



总结

通过近一周的作业,理解了类的调用,熟悉了mvc的结构,熟悉了mysql数据库的操作。

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议