【发布时间】:2019-02-21 04:01:11
【问题描述】:
我正在尝试回显插入到我的数据库中的信息。由于我对 php 编码很陌生,我不太确定我是如何做到这一点的。我的数据库名称是“nyheter”,表是“post”。所以我想从 db 中选择数据并在页面上回显。
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "", "nyheter");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
//get results from database
$result = mysqli_query($connection,"SELECT * FROM post");
$all_property = array(); //declare an array for saving property
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<link rel="stylesheet" href="nyheter.css" type="text/css" />
<link rel="stylesheet" href="read.css">
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="jquery.dynamicmaxheight.js"></script>
</head>
<body>
<div class="allt-2">
<div class="content">
<img src="http://cdn4.iconfinder.com/data/icons/socialmediaicons_v120/48/google.png"/ alt="" >
<h3><?php echo $Name?></h3>
</div>
<section class="section js-dynamic-height" data-maxheight="150" >
<p class="dynamic-height-wrap"> Hej
</p>
<button class="js-dynamic-show-hide button" title="Läs mer" data-replace-text="Läs mindre">Läs mer</button>
</section>
<img class="ny-img" src="http://placehold.it/500x320"/>
</div>
</body>
<script>
$(document).ready(function(){
$('.js-dynamic-height').dynamicMaxHeight();
});
</script>
</body>
</html>
【问题讨论】:
-
究竟是什么不工作?你有错误吗?如果是这样,它们是什么?你什么都没看到吗?我们需要更多信息。
-
不,我没有收到任何错误,它只是不会将数据回显到
标题。
-
你在哪里定义
$name? -
在您的代码中尝试编写类似这样的内容,其中您回显名称: if (mysqli_num_rows($result) > 0) { //在此处执行您的代码或在此处回显您的名称 }else{ //显示这里有错误; }
-
在 addpost.php.