我有一个数据库IN MYSQL,我希望从中检索数据并将其打印出来,我该怎么做? 其中的列是标题和博客。我希望将标题内容打印为段落中的标题和博客内容。
答案 0 :(得分:-1)
答案 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);
?>
使用以下链接
答案 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);
?>