在我的Android應用我通過PHP腳本返回從我的MySQL數據庫的一些數據,如果返回的結果爲空:如何從返回的php結果中刪除標籤?
result<br /><font size='1'><table class='xdebug-error' 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 variable: output in C:\wamp\www\y.php on line <i>16</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.0005</td><td bgcolor='#eeeeec' align='right'>368264</td><td bgcolor='#eeeeec'>{main}()</td><td title='C:\wamp\www\y.php' bgcolor='#eeeeec'>..\y.php<b>:</b>0</td></tr></table></font>" not exist"
這個詞:它會以這種格式返回給我的應用程序「不存在「我添加它在我的PHP通過if語句檢查結果,如果它的null,我想用」不存在「的字符串值替換它,並在我的應用程序中,我將處理它,而不是處理空值,這將導致JSON異常,因爲這個有價值的空值或值不能被解析爲JSON數組我的問題是:我如何刪除所有返回的結果標籤?如果$輸出爲空,我將它替換爲「不存在」,但它沒有以JSON格式返回,因爲它具有值,爲什麼?請幫助我,因爲我在PHP中新...
PHP代碼
$name=$_REQUEST['Name'];
mysql_connect("localhost","user","pass")or OnError('database connection failed', mysql_error());
mysql_select_db("MYDB")or OnError('database selection failed', mysql_error($mysql));
mysql_query("SET NAMES utf8");
$sql=mysql_query("select burnedCalories from Exercise where Name='$name' ");
while($row=mysql_fetch_assoc($sql))
$output[]=$row;
if (is_null($output)) // if the exercise name not exist the result will be null
{
$output = ' not exist';
}
print(json_encode($output));
mysql_close();
define('DEBUG_DETAILS', true);
function onError($msg, $details) {
$msg = array(
'status'=>'error',
'message'=>$msg);
if (defined('DEBUG_DETAILS') && DEBUG_DETAILS) {
$msg['details'] = $details;
}
die(json_encode($msg));}
?>