I'm using this simple PHP code below to read data from my module's table, but can't do the same thing using Magento codes.
Tried to do that using different articles but was either getting errors or the whole table structure was displayed in the page instead of just the information.
How can I do that?
<?php
$servername = "localhost";
$username = "username";
$password = "";
$dbname = "dbname";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT comment_txt, name, comment_date FROM mytablename where productcomment_increment_id='$productId' && comment_status='Approved'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<i><b>Author Name:</b></i>";
echo $row["name"];
echo "<br /><i><b> Comment: </i></b>";
echo $row["comment_txt"];
echo "<br /><i><b>Date: </i></b>";
echo $row["comment_date"];
echo "<br><br>";
}
} else {
//echo "0 results";
}
$conn->close();
?>
I will greatly appreciate helpful answers.