从数据库表调用信息时,HTML表正在添加其他行

时间:2015-11-27 10:32:06

标签: php html database html-table row

我的HTML格式似乎有问题。我正在调用数据库来显示网页上表格中的所有信息。我已经掌握了相关信息。不幸的是,该表在表的底部添加了一行,产生了4行,而实际上在数据库中只显示了3行。

知道为什么?

<?php
//connect to the server
$link = mysql_connect('*****', '*****', '****'); 
if (!$link) { 
    die('Could not connect: ' . mysql_error()); 
}

mysql_select_db('******'); 

$query = mysql_query("SELECT * FROM tablename");

        echo "<table border='1'>
            <tr>
            <td>Date</td>
            <td>Region</td>
            <td>Cameraman</td>
            <td>Livestream?</td>
            <td>Event Title</td>
            <td>Lecturer</td>
            <td>Time</td>
            <td>Speaker</td>
            <td>ICE Contact</td>
            <td>Venue Address</td>
            <td>Venue Contact</td>
            <td>Additional Comments</td>
            <td>On App?</td>
            </tr>";

        WHILE($rows = mysql_fetch_array($query)):

            echo "<tr>";
            echo "<td>" . $rows['date'] . "</td>";
            echo "<td>" . $rows['region'] . "</td>"; 
            echo "<td>" . $rows['cameraman'] . "</td>";
            echo "<td>" . $rows['livestream'] . "</td>"; 
            echo "<td>" . $rows['eventitle'] . "</td>";
            echo "<td>" . $rows['lecturer'] . "</td>"; 
            echo "<td>" . $rows['time'] . "</td>";
            echo "<td>" . $rows['speaker'] . "</td>";
            echo "<td>" . $rows['icecontact'] . "</td>";
            echo "<td>" . $rows['venueaddress'] . "</td>"; 
            echo "<td>" . $rows['venuecontact'] . "</td>";
            echo "<td>" . $rows['additioncomments'] . "</td>";  
            echo "<td>" . $rows['onapp'] . "</td>";     
            echo "</tr>";


        endwhile;
            echo "</table>";

?>

我已将链接添加到以下页面。

http://cpdonline.tv/spreadsheet/spreadsheet.php

3 个答案:

答案 0 :(得分:0)

您的数据库中似乎有空数据,因为许多行都是空的

答案 1 :(得分:0)

检查数据库是否有空记录或运行查询

DELETE FROM table_name WHERE column='';

答案 2 :(得分:0)

使用以下内容更新您的while循环:

WHILE($rows = mysql_fetch_array($query)):
            $rows = array_filter($rows);
            if (!empty($rows)) {
                echo "<tr>";
                echo "<td>" . $rows['date'] . "</td>";
                echo "<td>" . $rows['region'] . "</td>"; 
                echo "<td>" . $rows['cameraman'] . "</td>";
                echo "<td>" . $rows['livestream'] . "</td>"; 
                echo "<td>" . $rows['eventitle'] . "</td>";
                echo "<td>" . $rows['lecturer'] . "</td>"; 
                echo "<td>" . $rows['time'] . "</td>";
                echo "<td>" . $rows['speaker'] . "</td>";
                echo "<td>" . $rows['icecontact'] . "</td>";
                echo "<td>" . $rows['venueaddress'] . "</td>"; 
                echo "<td>" . $rows['venuecontact'] . "</td>";
                echo "<td>" . $rows['additioncomments'] . "</td>";  
                echo "<td>" . $rows['onapp'] . "</td>";     
                echo "</tr>";
            }
            endwhile;
            echo "</table>";

array_filter()函数的默认行为将从数组中删除所有等于null, 0, '' or false.的值