1

How do I edit the three div's using CSS so that the result will be a table like the following picture (but in a better way. I created that table using Microsoft Word)

enter image description here

<?php
        $servername = "localhost";
        $username = "root";
        $password = "";
        $dbname = "hangman";

        try {
            $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
            $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $stmt = $conn->prepare("SELECT * FROM `credits`");
            $stmt->execute();

            $result = $stmt->fetch(PDO::FETCH_ASSOC);
            echo "<div>Created By: ".$result["author_name"]."<br></div>";
            echo "<div>Contact: ".$result["author_email"]."<br></div>";
            echo "<div>Description: ".$result["description"]."</div>";
        }
        catch(PDOException $e) {
            echo "Error: " . $e->getMessage();
        }
        $conn = null;
    ?>
1
  • 3
    Tables don't just get automagically created using CSS. Change your divs to tables instead. Commented Nov 18, 2015 at 13:36

1 Answer 1

1
    <?php
        $servername = "localhost";
        $username = "root";
        $password = "";
        $dbname = "hangman";
    ?>
      <table>
          <td>Created By</td>
          <td>Contact</td>
          <td>Description</td>
<?php
        try {
            $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
            $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $stmt = $conn->prepare("SELECT * FROM `credits`");
            $stmt->execute();

            $result = $stmt->fetch(PDO::FETCH_ASSOC);
            echo "<tr>";
            echo "<td>".$result["author_name"]."</td>";
            echo "<td>".$result["author_email"]."</td>";
            echo "<td>".$result["description"]."</td>";
            echo "</tr>";
        }
        catch(PDOException $e) {
            echo "Error: " . $e->getMessage();
        }
        $conn = null;
    ?>
</table>

I think you asking this. Try above code.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you please accept this as answer @LybinPeterBabu
You seem to be missing some <tr>'s there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.