Mysql - 如何从数据库(mysql)中检索数据并打印出来。(php)

时间:2014-04-25 09:57:30

标签: php mysql

我有一个数据库IN MYSQL,我希望从中检索数据并将其打印出来,我该怎么做? 其中的列是标题和博客。我希望将标题内容打印为段落中的标题和博客内容。

3 个答案:

答案 0 :(得分:-1)

要检索数据,请使用“选择”

select title,blogs from table name

http://dev.mysql.com/doc/refman/5.6/en/select.html

答案 1 :(得分:-1)

<?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);
?>

使用以下链接

http://www.w3schools.com/php/php_mysql_select.asp

答案 2 :(得分:-1)

确定。这里。

<?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);

?>