[英]How to retrieve mysql data and display it in html
I've created a database in mysql. 我已经在mysql中创建了一个数据库。 It works. 有用。 When a user goes to /upload.html...the user enters details: 当用户转到/upload.html ...时,用户输入详细信息:
first name :
last name:
email address:
and it gets stored in test2 database and person_list table. 并将其存储在test2数据库和person_list表中。 I've checked and it works. 我已经检查了并且可以正常工作。
However I'm trying to display this data on /download.html 但是我试图在/download.html上显示此数据
the data doesn't populate in the tables. 数据不会填充在表格中。
I'm trying to get it to look like this: 我正在尝试使其看起来像这样:
first name
Last name
email
first name
last name
email
first name
last name
email and so forth...
I'm fairly new to php...and I know there are mistakes in this code..but can't pinpoint where.. 我对php很陌生...我知道这段代码中有错误..但无法查明位置..
I keep getting this: the php code keeps displaying in the page instead of the data showing in the tables 我不断得到这个:php代码一直显示在页面中,而不是表中显示的数据
this is download.html 这是download.html
---html code---
<?php
$hostdb = '************';
$namedb = 'test2';
$userdb = '**********';
$passdb = '********';
try {
$conn = new PDO("mysql:host=$hostdb; dbname=$*****", $userdb, $passdb);
$conn->exec("SET CHARACTER SET utf8");
$sql = "SELECT `firstname`, `lastname`, `email` FROM `person_list` WHERE `person_list'";
$result = $conn->query($sql);
if($result !== false) {
$html_table = '<table border="1" cellspacing="0" cellpadding="2"><tr><th>First Name</th><th>Last Name</th><th>Email Address</th></tr>';
foreach($result as $row) {
$html_table .= '<tr><td>' .$row['firstname']. '</td><td>' .$row['lastname']. '</td><td>' .$row['email']. '</td></tr>';
}
}
$conn = null;
$html_table .= '</table>';
echo $html_table;
}
catch(PDOException $e) {
echo $e->getMessage();
}
?>
</html>
In the query: 在查询中:
$sql = "SELECT `firstname`, `lastname`, `email`
FROM `person_list`
WHERE `person_list'";
You have a quote in person_list'
<= which should be a tick ` 您在person_list'
有一个引号person_list'
<=应该是一个勾号`
Either replace the quote with a tick, or just remove it. 要么将报价单打勾,要么将其删除。
Like this: 像这样:
$sql = "SELECT firstname, lastname, email
FROM person_list
WHERE person_list";
And add the where condition 并添加where条件
WHERE person_list = value;
1st: your statement is wrong at the where statment 第一:您的陈述在where陈述中是错误的
$sql = "SELECT `firstname`, `lastname`, `email` FROM `person_list` ;";
or 要么
$sql = "SELECT * FROM person_list WHERE (column_name = 'something');";
2nd for seprationg: 分隔第二名:
index.php::: index.php文件:::
<?php require_once("phpcode.php"); ?>
<html>......</html>
phpcode.php phpcode.php
<?php
................
?>
3rd: displaying- 第三:显示-
<html>...
<table>
<tr>
<th>name</th>
<th>email</th>
</tr>
<?php while ($data=$results->fetch_assoc())
{
print "
<tr>
<td>".$data['username']."</td>
<td>".$data['email']."</td>
</tr>
";
?>
</table>
....</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.