簡體   English   中英

Mysql - 如何從數據庫(mysql)中檢索數據並打印它。(php)

[英]Mysql - how to retrieve data from a database(mysql) and print it.(php)

我在 MYSQL 中有一個數據庫,我希望從中檢索數據並打印它,我該怎么做? 其中的列是標題和博客。 我希望將標題內容打印為段落中的標題和博客內容。

要檢索數據,請使用“選擇”

select title,blogs from table name

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

使用以下鏈接

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

好的。 這里。

<?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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM