duanping2005 2012-08-07 22:15
浏览 165

将json数据插入到列表中的html页面中

I'm trying to get information from mysql and post the information into an html page. Here's what I've got so far:This is my tenantlistmob.php

  <?php 
  include('connection.php');
  $result = mysql_query("SELECT * FROM tenanttemp");

  while ($row = mysql_fetch_assoc($result)) 
 {
   $array[] = array($row['TenantFirstName']);
  }
echo json_encode($array);
 ?>

When i call tenantlistmob from browser directly it shows [["Humayun"],["Sahjahan"],["Bayezid"],["Bayezid"],["Asaduzzaman"],["Mouri"]] where firstnames are comming. I like to use this name in html page. my html page is

<!DOCTYPE HTML>
<html>
<link rel="stylesheet" href="styles/main.css" />
<script type="text/javascript" src="jquery.js"></script> 
<body>
 <div id="output">this element will be accessed by jquery and this text replaced</div>
<script id="source" type="text/javascript">
 $(function () 
 {
$.ajax({                                      
  url: 'tenantlistmob.php',                
  data: "",                        
  dataType: 'json',                 
  success: function(data)          
  {
    var id = data;              
   //var vname = data[1];           //get name
    $.each(id, function (val)
   {        
     $('#output').html(""+id);
    });
  } 
});
}); 

</script>
<form id="formset">
<fieldset id="fieldset">
<h3 align="center">Tenant List</h3><hr/>
<a href="#">name1</a><br /><hr/>
<a href="#">name2 </a> <br /><hr/>
</fieldset>
</form>
<a id="box-link1" class="myButtonLink"  href="category1.php"></a> 
</div>    
 </body>
</html> 

My output(main.css) is like this

#output
{
color:#ffffff;
font-size : 20px;
margin : 0;
letter-spacing:1px;
width:480px;
}

I am getting the first name asHumayun,Sahjahan,Bayezid,Bayezid,Asaduzzaman,Mouri in top-left corner. But i like to get the name as list(name1,name2) with link. when i click on a name(name1,name2) it will show details of the name. How can I do this?

Thank in advance

  • 写回答

2条回答 默认 最新

  • duanlangwen9597 2012-08-07 22:23
    关注

    Try this:

    <?php 
      include('connection.php');
      $result = mysql_query("SELECT * FROM tenanttemp");
    
      $array = array();
      while ($row = mysql_fetch_assoc($result)) 
       {
         $array[] = $row['TenantFirstName'];
       }
      echo json_encode($array);
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀