我正在尝试从数据库中获取数据但是每当我尝试运行脚本时,表单的数据都会被解除。实际上这个表单将显示技术新闻。它应该是正确的对称但我无法使这个页面适当对称请帮助我。 HTML代码
<html>
<head>
<title> News</title>
<link rel="stylesheet" href="stylesheet/style1.css" type="text/css" />
</head>
<body>
<div id="outer">
<div id='InnerPage'>
<div class="clear"></div>
<div id="ContentWrappertutorial">
<div id="firstSection">
<div id="TechNewsLeft">
<h1>News</h1>
<?php
$q = "select * from technews order by time desc";
$run = mysqli_query($con, $q);
while ($fetch = mysqli_fetch_array($run)){
?>
<div id="containerfortechnews">
<div class="part1_partition1">
<img src="newsImages/<?php echo $fetch[2]; ?>" width="320px" height="260px"/>
</div>
<div class="part2_partition1">
<div class="underpartition1">
<h3><?php echo $fetch[1]; ?></h3>
</div>
<div class="underpartition2">
<?php
$string = substr($fetch[3], 0, 100);
echo "<p>".$string."...<a href='#'> know more</a></p>"; ?>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
CSS代码: -
#InnerPage{
width: 1320px;
margin: auto;
height: auto;
background-color: transparent;
}
#firstSection{
height: auto;
width:100%;
background-color: transparent;
}
#TechNewsLeft{
width: 1318px;
height: auto;
float: left;
background-color: silver;
}
#TechNewsLeft h1{
text-align: center;
padding-top: 15px;
padding-bottom: 15px;
}
#containerfortechnews{
width:100%;
height:100%;
}
.part1_partition1{
height: 260px;
width: 320px;
background-color: white;
border: 1px solid black;
float: left;
}
.part2_partition1{
height: 260px;
width: 600px;
background-color: white;
float: left;
}
.underpartition1{
height: 90px;
width: 600px;
background-color: whitesmoke;
text-align: center;
}
.underpartition2{
height: 170px;
width: 600px;
background-color:whitesmoke;
}
答案 0 :(得分:0)
如果页面呈现没有错误,那么此页面上的代码就可以了。也许错误在于查询
select * from technews order by time desc
如果time
的数据类型为varchar
,那么您不能指望正确的排序。这可能有效:
select * from technews order by cast(time as DATE) desc