I have a database IN MYSQL from where I wish to retrieve data and print it, how do I do it? 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
<?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
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);
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.