[英]Mysql - how to retrieve data from a database(mysql) and print it.(php)
我在 MYSQL 中有一個數據庫,我希望從中檢索數據並打印它,我該怎么做? 其中的列是標題和博客。 我希望將標題內容打印為段落中的標題和博客內容。
<?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);
?>
使用以下鏈接
好的。 這里。
<?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.