newsList.php
Thu Nov 26 2020 14:50:56 GMT+0000 (Coordinated Universal Time)
Saved by @uchenliew #php
<html lang="en">
<head>
<!--using external files-->
<?php require('import.html'); ?>
<title>U Chen Daily | All News</title>
</head>
<style>
@media only screen and (min-width: 893px) {
.card-img-top{
width: 100%;
height: 15vw;
object-fit: cover;
}
}
.card-body{
background: #1f52a3;
}
.card-footer{
background: #1f52a3;
}
.h5{
color: #1f52a3;
}
.card-text{
font-size: 12px;
}
</style>
<body class="bg-light">
<!--using external files-->
<?php require('header.php'); ?>
<div class="container" style="margin: 20px;">
<div class="row">
<div class="col-sm"><h3 style="color: #1f52a3;">All News</h3></div>
</div>
</div>
<div class="container-fluid bg-light" style="padding: 30px 10px;">
<div class="row d-flex justify-content-start" style="margin: 0 10px;">
<?php
$dbc = mysqli_connect('localhost', 'root', ''); //connect database
mysqli_select_db($dbc, 'news'); //select database
$query = 'SELECT * FROM news ORDER BY news_datetime DESC';
$runQuery = mysqli_query($dbc, $query);
?>
<?php
if($runQuery){
foreach($runQuery as $row){
?>
<div class="card" style="width: 22rem; margin: 20px 30px;">
<img class="card-img-top" src="<?php
if(empty($row['news_image'])){
echo 'https://via.placeholder.com/350x250';
}else{
echo $row['news_image'];
}
?>" alt="Card image cap">
<div class="card-body">
<a href="/205CDE/Assignment/news.php?id=<?php echo $row['news_id']; ?>">
<h5 class="card-title text-uppercase text-light d-md-none d-lg-block">
<?php
if(strlen($row['news_title']) > 50){
echo substr($row['news_title'], 0, 50).'...';
}else{
echo $row['news_title'];
}
?>
</h5>
<h5 class="card-title text-uppercase text-light d-none d-md-block d-lg-none">
<?php
if(strlen($row['news_title']) > 106){
echo substr($row['news_title'], 0, 106).'...';
}else{
echo $row['news_title'];
}
?>
</h5>
</a>
</div>
<div class="card-footer border-0">
<div class="row">
<div class="col-6 card-text text-light text-uppercase"><i class="fas fa-hashtag"></i>
<?php echo $row['news_category']; ?>
</div>
<div class="col-6 card-text text-light text-right text-uppercase"><i class="far fa-clock"></i>
<?php echo date('d-M-Y', strtotime($row['news_datetime']));?>
</div>
</div>
</div>
</div>
<?php
}
}else{
echo "ERROR! No record found!";
}
mysqli_close($dbc);
?>
</div>
</div>
<!--using external files-->
<?php require('footer.html'); ?>
</body>
</html>



Comments