Php 为什么不是';我的MySQL数据是否显示在我的表中?

Php 为什么不是';我的MySQL数据是否显示在我的表中?,php,mysql,html-table,Php,Mysql,Html Table,为什么我的MySQL数据没有显示在我的表中?一切似乎都很好,只是我的数据(一个鸟名列表之类的)没有显示出来。我需要一些能看到我的错误所在的新眼睛,是的,我知道可能有更简单的方法来做到这一点,但这是我的任务所需要的,所以请不要提供其他方法来做到这一点。我所需要的只是帮助将数据填充到HTML表中。我的PHP代码如下: PHP代码 <?php $pageTitle = 'Mod06 Pagination| Jason McCoy '; include('includes/head

为什么我的MySQL数据没有显示在我的表中?一切似乎都很好,只是我的数据(一个鸟名列表之类的)没有显示出来。我需要一些能看到我的错误所在的新眼睛,是的,我知道可能有更简单的方法来做到这一点,但这是我的任务所需要的,所以请不要提供其他方法来做到这一点。我所需要的只是帮助将数据填充到HTML表中。我的PHP代码如下:

PHP代码

<?php
    $pageTitle = 'Mod06 Pagination| Jason McCoy ';
    include('includes/header.inc.php');
    include ('includes/db_connect.inc.php');

    $display = 8;

    // Determine how many pages there are...

    if (isset($_GET['p']) && is_numeric($_GET['p'])) { // Already been determined.
        $pages = $_GET['pages'];
    } else { 
        $query = "SELECT COUNT(birdID) FROM birds";
        $result = @mysqli_query($dbc, $query);
        $row = @mysqli_fetch_array($result, MYSQLI_NUM);
        $records = $row[0];
    }

    // Calculate the number of pages...

    if ($records > $display) { 
        $pages = ceil($records/$display);
    } else {
        $pages = 1;
    }

    // Determine where in the database to start returning results...

    if (isset($_GET['s']) && is_numeric($_GET['s'])) {
        $start = $_GET['s'];
    } else {
        $start = 0;
    }

    // Sort the columns 
    // Default is birdID

        $sortDefault = 'birdID';

        // Create an array for the columns

        $sortColumns = array('birdID', 'nameGeneral', 'nameSpecific', 'populationTrend');

        // Define sortable query ASC DESC

        $sort =  (isset($_GET['sort'])) && in_array($_GET['sort'], $sortColumns) ? $_GET['sort']: $sortDefault;
        $order = (isset($_GET['order']) && strcasecmp($_GET['order'], 'DESC') == 0) ? 'DESC' : 'ASC';

        // Run the query 

    $query = "SELECT birdID, nameGeneral, nameSpecific, populationTrend FROM birds ORDER BY $order LIMIT $start, $display";
    $result = @mysqli_query($dbc, $query);       
?>

    <!-- Table header: -->
    <table align="center" cellspacing="0" cellpadding="5" width="80%">
        <tr>
            <th><a href='index.php?sort=birdID&order=<?php echo $order == 'DESC' ? 'ASC' : 'DESC' ?>'>Bird<?
                            if($_GET["order"]=="ASC" && $_GET["sort"]=="birdID"){
                                echo '<img src="images/downArrow.jpg" id="birdASC" name="birdASC" style="margin:-15px 0 0 13px;" width="18px" height="18px">';
                            } else {
                    echo '<img src="images/upArrow.jpg" id="birdDESC" name="birdDESC" style="margin:-15px 0 0 13px;" width="18px" height="18px">';
                }?></a></th>
            <th><a href='index.php?sort=nameGeneral&order=<?php echo $order == 'DESC' ? 'ASC' : 'DESC' ?>'>General Name<?
                            if($_GET["order"]=="ASC" && $_GET["sort"]=="nameGeneral"){
                                echo '<img src="images/downArrow.jpg" id="nameGeneralASC" name="nameGeneralASC" style="margin:-15px 0 0 13px;" width="18px" height="18px">';
                            } else {
                    echo '<img src="images/upArrow.jpg" id="nameGeneralDESC" name="birdDESC" style="margin:-15px 0 0 13px;" width="18px" height="18px">';
                }?></a></th>
            <th><a href='index.php?sort=nameSpecific&order=<?php echo $order == 'DESC' ? 'ASC' : 'DESC' ?>'>Name Specific<?
                            if($_GET["order"]=="ASC" && $_GET["sort"]=="nameSpecific"){
                                echo '<img src="images/downArrow.jpg" id="nameSpecificASC" name="nameSpecificASC" style="margin:-15px 0 0 13px;" width="18px" height="18px">';
                            } else {
                    echo '<img src="images/upArrow.jpg" id="nameSpecificDESC" name="birdDESC" style="margin:-15px 0 0 13px;" width="18px" height="18px">';
                }?></a></th>
            <th><a href='index.php?sort=populationTrend&order=<?php echo $order == 'DESC' ? 'ASC' : 'DESC' ?>'>Population Trend<?
                            if($_GET["order"]=="ASC" && $_GET["sort"]=="populationTrend"){
                                echo '<img src="images/downArrow.jpg" id="populationTrendASC" name="populationTrendASC" style="margin:-15px 0 0 13px;" width="18px" height="18px">';
                            } else {
                    echo '<img src="images/upArrow.jpg" id="populationTrendDESC" name="birdDESC" style="margin:-15px 0 0 13px;" width="18px" height="18px">';
                }?></a></th>
        </tr>
<?php

    // Display the database results in the table...

    while ($row = @mysqli_fetch_array($result, MYSQL_ASSOC)) {
        echo '<tr>
            <td align="left">$row[birdID]</td>
            <td align="left">$row[nameGeneral]</td>
            <td align="left">$row[nameSpecific]</td>
            <td align="left">$row[populationTrend]</td>
         <tr>';
    } 

    echo '</table>';    
    mysqli_close($dbc);

    // Make the links to other pages, if necessary.
    if ($pages > 1) {
        echo '<br /><p>';
        $currentPage = ($start/$display) + 1;
    // If it's not the first page, make a Previous button:
    if ($currentPage != 1) {
        echo '<a href="index.php?s=' . ($start - $display) . '&pages=' . $pages . '&sort=' . $sort . '">Previous</a> ';
    }
    // Make all the numbered pages:
    for ($i = 1; $i <= $pages; $i++) {
        if ($i != $currentPage) {
            echo '<a href="index.php?s=' . (($display * ($i - 1))) . '&pages=' . $pages . '&sort=' . $sort . '">' . $i . '</a> ';
        } else {
            echo $i . ' ';
        }
    } // End of FOR loop.

    // If it's not the last page, make a Next button:
    if ($currentPage != $pages) {
        echo '<a href="index.php?s=' . ($start + $display) . '&pages=' . $pages . '&sort=' . $sort . '">Next</a>';
    }

    echo '</p>'; 

} 

    include('includes/footer.inc.php');
?>


</div>
</body>
</html>

使用
像这样在echo内部使用
,因为不显示数据库中的值

while ($row = @mysqli_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr>
        <td align=\"left\">$row[birdID]</td>
        <td align=\"left\">$row[nameGeneral]</td>
        <td align=\"left\">$row[nameSpecific]</td>
        <td align=\"left\">$row[populationTrend]</td>
     <tr>";
} 
while($row=@mysqli\u fetch\u数组($result,MYSQL\u ASSOC)){
回声“
$row[birdID]
$row[名称概述]
$row[指定名称]
$row[人口趋势]
";
} 

将这张
$row[birdID]
改为
$row['birdID']
总之,你错过了
'

对不起,如果有点简练的话,在手机上打字

“$row[birdID]”

其他部分应适当重写为:

“$row['birdID']”

因为birdID是一个字符串,而不是一个变量名

尽管PHP将其用作字符串,但如果当前作用域中没有具有该名称的变量,则使用该字符串

始终在字符串文字数组索引周围使用引号。例如,$foo['bar']是 没错,$foo[bar]不是。但是为什么呢?遇到这种情况很常见 旧脚本中的语法

从PHP文档中:


编辑有人指出了echo中使用的单引号,这也是一个问题。使用单引号时,PHP不会解释字符串的内容,而使用双引号时,PHP将解析字符串,并正确使用值。

感谢您的帮助,但这不起作用,它会返回一个错误。如果您你想看看当前显示的内容:我得到了这个错误解析错误:语法错误,意外的T_-ENCAPSED_和_-WHITESPACE,在/home/jkm1972/public_-html/AB-Tech/web250/Mod06/McCoy_-Mod06/index.php第92行中需要T_字符串或T_变量或T_-NUM_字符串。我理解你的意思,但你的建议不起作用。我只是在想-MySQL不是只使用小写的表名和列名吗?请尝试使用“birdid”而不是“birdid”,等等。遗憾的是,我现在没有MySQL来测试这一点。另外,请尝试在MySQL workbench或PHPMyAdmin中运行查询本身-无论您使用哪一个…我现在已经正确显示了数据,但排序不起作用