【发布时间】:2018-05-18 14:07:32
【问题描述】:
我正在尝试使用PHP 从SQL 源输出Grid,但它不起作用。
这是我在控制台中遇到的错误:
[W] For WAI-ARIA compliance, IMG elements SHOULD have an alt attribute.
[E] Ext.JSON.decode(): You're trying to decode an invalid JSON String:
<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: id in C:\wamp64\www\EmployeeMenu\_data\employee\Read_employee.php on line <i>14</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0019</td><td bgcolor='#eeeeec' align='right'>242280</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp64\www\EmployeeMenu\_data\employee\Read_employee.php' bgcolor='#eeeeec'>...\Read_employee.php<b>:</b>0</td></tr>
</table></font>
<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: id in C:\wamp64\www\EmployeeMenu\_data\employee\Read_employee.php on line <i>14</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0019</td><td bgcolor='#eeeeec' align='right'>242280</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp64\www\EmployeeMenu\_data\employee\Read_employee.php' bgcolor='#eeeeec'>...\Read_employee.php<b>:</b>0</td></tr>
</table></font>
[{"id":null,"firstname":"Alain","lastname":"Doyon","title":"Project Manager","businessunit":"Dev","experience":"7"},{"id":null,"firstname":"Joel","lastname":"Deslauriers","title":"Integrator Senior","businessunit":"Kappa","experience":"5"}]
这是我的 PHP 文件:
<?php
require_once"..//..//_includes/headers.php";
$query = "select firstname, lastname, title, businessunit, experience from
employee_tab order by businessunit";
logit($query);
$result = odbc_exec($connection,$query);
$cnt = 0;
while($row = odbc_fetch_array($result))
{
$cnt = $cnt + 1;
$myArray[] = array(
'id'=>$row['id'],
'firstname'=>$row['firstname'],
'lastname'=>$row['lastname'],
'title'=>$row['title'],
'businessunit'=>$row['businessunit'],
'experience'=>$row['experience'],
);
}
if (isset($myArray))
{
if ( sizeof($myArray) > 0 )
{
$output = json_encode($myArray);
echo $output;
}
else
{
echo '(success:true,"error":0)';
}
}
else
{
echo '(success:true,"error":0)';
}
?>
感谢您的帮助。
【问题讨论】:
-
结果集中有'id'吗?尝试不使用 'id'=>$row['id']。
-
你的 PHP 输出以一个通知开头,它永远不是一个有效的 Json。您应该遵循通知并“清理”您的 php 代码。
-
此外,您仅在“echo $output”时回显有效的json,否则您的回显不会输出有效的json。
-
您好,请删除通知和 tje rowid,因为我的这部分代码没有使用 ID 列,它工作正常。感谢您的帮助。
标签: php sql-server extjs sencha-architect