如何使用CSS编辑PHP内的div

时间:2015-11-18 13:34:46

标签: php css

如何使用CSS编辑三个div,以便结果为表like the following picture (但更好的方式。我使用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 个答案:

答案 0 :(得分: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>

我想你问这个。试试上面的代码。