[Solved] How to print info from mysql db [closed]


If I understand your question correctly you could try something like the following.

Edit: taken into account you already have a connection in config.php

In config.php make sure you have the following.

<?php 
    $con=mysqli_connect("hostname","username","password","database");

    if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }
?>

And then on the page where you want to display the results add.

 <?php

    include_once("config.php"); //Can be removed if already added.

    $query = "SELECT Product_Name, Product_Description, Product_Description2 FROM tablename";

    $result = mysqli_query($con,$query);

      echo "<table border="1"><tr><th>Name</th><th>Product_Description</th><th>Product_Description2</th></tr>";

    while($row = mysqli_fetch_assoc($result))
      {
      echo "<tr>";
      echo "<td>" . $row['Product_Name'] . "</td>";
      echo "<td>" . $row['Product_Description'] . "</td>";
      echo "<td>" . $row['Product_Description2'] . "</td>";
      echo "</tr>";
      }
      echo "</table>";

    mysqli_close($con);
    ?> 

Edit2: Get product info by id

If you want to get a product by ID Try changing the query to.

"SELECT Product_Name, Product_Description, Product_Description2 FROM tablename WHERE Product_id = '$id'";

3

solved How to print info from mysql db [closed]