显示没有表的SQL数据

时间:2016-07-13 08:12:12

标签: php mysql

我正在制作一个页面,以显示发布给某些机构的问题的答案。我已成功地在表格中显示内容(从SQL表导入),但由于其性质,为了更好的可读性,我想以不同的格式显示它,其中每个答案都成功完成每个问题,作为一个段落,就像你在笔记本上写的一样。如何更改代码? enter image description here

            <?php
                        $servername="localhost";
                        $username="root";
                        $password='';
                        $conn=mysql_connect($servername, $username, $password) or die ("Error connecting to mysql server: ".mysql_error());
                        $dbname = 'bsp';   
                        mysql_select_db($dbname, $conn) or die ("Error selecting specified database on mysql server: ".mysql_error());
                        $sql = "SELECT query,answer FROM answers";
                        $result=mysql_query($sql) or die ("Query to get data from firsttable failed: ".mysql_error());
                     echo "<table>";
                    echo '<tr><th class="one">Query</th>
                        <th class="two">Answer</th>';

                echo "</tr>";
                while ($row=mysql_fetch_array($result)) 
                {
                    $query=$row["query"];
                    $answer=$row["answer"];
                    echo "<tr>";
                    echo "<td>$query</td>
                           <td>$answer</td>";
                            echo "</tr>";        
                }
            echo "</table><br>";        
            ?>

1 个答案:

答案 0 :(得分:2)

while ($row=mysql_fetch_array($result)) 
{
    echo "<p><strong>$row['query']</strong><br>$row['answer']</p>";      
}