[英]Mysql - how to retrieve data from a database(mysql) and print it.(php)
I have a database IN MYSQL from where I wish to retrieve data and print it, how do I do it?我在 MYSQL 中有一个数据库,我希望从中检索数据并打印它,我该怎么做? The columns in it are title and blogs.
其中的列是标题和博客。 I wish to print the title content as the heading and the blog content in a paragraph.
我希望将标题内容打印为段落中的标题和博客内容。
To retrieve the data , use "select"要检索数据,请使用“选择”
select title,blogs from table name
http://dev.mysql.com/doc/refman/5.6/en/select.html http://dev.mysql.com/doc/refman/5.6/en/select.html
<?php
$con=mysqli_connect("example.com","peter","abc123","my_db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Persons");
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Use following links使用以下链接
http://www.w3schools.com/php/php_mysql_select.asp http://www.w3schools.com/php/php_mysql_select.asp
Ok.好的。 Here.
这里。
<?php
$con=mysqli_connect("hostname","username","password","databasename");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT blogs, title FROM tableName");
while($row = mysqli_fetch_array($result)) {
echo "<h1>".$row['title']."</h1>";
echo "<p>".$row['blogs']."</p>";
}
mysqli_close($con);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.