我似乎不明白为什么我有这些未定义的索引通知

时间:2013-05-06 11:02:40

标签: php

导致此未定义索引错误的原因或通知我到达我的页面

Notice: Undefined index: start_date in C:\xampp\htdocs\how are things\admin panel\daily.php on line 97

Notice: Undefined index: balance in C:\xampp\htdocs\how are things\admin panel\daily.php on line 98  

第97行和第98行的代码是

echo '<td>' . $row['start_date'] . '</td>';
echo '<td>' . $row['balance'] . '</td>';

这是我的整个代码

<?php

include'includes/connect.php';
 $allowedSorts = array('start_date', 'balance');

    $sort = isset($_GET['sort']) ? $_GET['sort'] : '';
    $result = "SELECT DATE_FORMAT(start_date, '%m-%d') AS 'month and day',balance as amount FROM `aggrement`";
    if(in_array($sort, $allowedSorts)){
         $result .= " ORDER BY {$sort}";
    }

    $result = mysql_query($result) or die(mysql_error());


echo "<table border='1' cellpadding='10'>";
echo "<tr>
<th><a href='view.php?sort=start_date'>month and day</th>
<th><a href='view.php?sort=balance'>Amount Paid</th>
</tr>";

while($row = mysql_fetch_array( $result ))
{

echo "<tr>";
echo '<td>' . $row['start_date'] . '</td>';
echo '<td>' . $row['balance'] . '</td>';
echo "</tr>";

}

echo "</table>";
?>

提前致谢

1 个答案:

答案 0 :(得分:2)

您正在为每个设置别名,因此您无法使用默认列名访问它们。

您必须使用别名来获取它们。喜欢

$row["month and day"]$row["amount"]