-2

是什么导致了这个未定义的索引错误或通知我进入我的页面

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>";
?>

提前致谢

4

1 回答 1

2

You're setting alias name for each one, so you can't access them with default columnname.

You must get them with alias name. Like

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

于 2013-05-06T11:10:08.360 回答