本文介绍了MySQL重新格式化mysql结果来满足json hansontable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据我以前解决的问题:。$ b
into
["Superior","Deluxe - City View","Deluxe - Balcony","Junior Suite","Andaman Studio"]
From these codes:
$sql_rName="select title from room_db where hotel='1' order by id asc";
$result_rName=mysql_db_query($dbname,$sql_rName);
while($rec_rName=mysql_fetch_array($result_rName)){
$_rName=$rec_rName['title'];
$_array[]=$_rName;
}
echo "{\"data\": ".json_encode($_array)."}";
mysql Table : room_db
Please suggest.
ps. Thanks to Olaf Dietsche for all of these help.
解决方案
To make a correct JSON, Try :`
$result="select title from room_db where hotel='1' order by id asc";
$messages = array();
while($message_data = mysql_fetch_assoc($result)) {
$message = array(
'id' => $message_data['userid'],
'title' => $message_data['title']
);
$messages[] = $message;
}
echo json_encode($messages);
}
`
and on the reseiver side do this :
`
data1=$.parseJSON(data);
if(data1.length===0){
$('#table > #table_body').append('<tr><td colspan="4" align="center" style="color:red">NO matching data </td></tr>');
}
else{
for(var i=0;i<data1.length;i++)
{
$('#table > #table_body').append('<tr id="' + data1[i]['id'] +'"> <td id="' + data1[i]['id'] +'" align="center" <td>'+data1[i]['title']+'</td> </tr>');
}
}
$('#table').append('</tbody>');
`
这篇关于MySQL重新格式化mysql结果来满足json hansontable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!