codeigniter---json解析


view部分

function ninep(i=0)
{   page=page+i;
  var data={page:page,thetype:thetype,place:place,thefind:thefind,flag:"1"};

      $.getJSON({
    method:"post",
    url:"http://localhost/realone/index.php/user/c_ninepic",
    data:data,
   success:function(res)
   {     
     res_tmp=res;
         // document.getElementById("ida1").innerHTML="<img src='http://localhost/realone/upload/1.png'>";
        var a1s=document.getElementsByClassName("dark");
                // document.getElementById("dark1").innerHTML="<span>"+res[0].name+"同学<br>于"+res[0].time+res[0].place+"<br>丢失"+res[0].lostname+"<span>";
        for(var i=0;i<res[0]['num'];i++)
        {   
        var m='t'+i;
          a1s[i].innerHTML="<span>"+res[i].name+"同学<br>于"+res[i].place+"<br>丢失"+res[i].lostname+"<span>";   
          document.getElementById(m).style.background='no-repeat url(http://localhost/realone/'+res[i].fname+')';          
        }
        if(res[0]['num']==0)
        {
          alert("暂无更多信息")
          if(page>1)
          page=page-1;    //过页减
        }
        else if (res[0]['num']<9)
        {  
           for(var i=res[0]['num'];i<9;i++)
           {
              var m='t'+i;
            a1s[i].innerHTML="<span>暂无更多信息<span>";   
            document.getElementById(m).style.background='no-repeat url(http://localhost/realone/upload/moren.png)';  
           }
        }      
   },

   error:function(err)
   {     
    console.log(err);
   }
   })
  }

controller部分

public function c_ninepic(){
	
	$res=null;
	$page=$this->input->post("page");
	$type=$this->input->post("thetype");
	$place=$this->input->post("place");
	$thefind=$this->input->post("thefind");
	$flag=$this->input->post("flag");
	$limst=($page-1)*9;
	$this->load->model('user_model');
	$res=$this->user_model->m_ninepic($limst,$type,$place,$thefind,$flag);
	$res[0]['num']=count($res);
	echo json_encode($res);
}

model部分

public function m_ninepic($limst,$type,$place,$thefind,$flag){
	// $sql="select fname,id from lost_message order by id desc limit 0,9";
 if($flag==1)
  $db="lost_message";

 if($flag==2)
  	$db="found_message";
  
	if($type==""&&$place==""&&$thefind=="")
	{$sql="select ".$db.".fname,".$db.".lostname,".$db.".id,".$db.".place,".$db.".time ,user_message.name from ".$db." inner join user_message on ".$db.".user_id=user_message.id order by ".$db.".id desc limit ".$limst.",9";}
else 
{
	$sql2="";
	if($type!="")
	{
		$sql2=$sql2."and ".$db.".type='".$type."'";
	}
	if($place!="")
	{
		$sql2=$sql2."and ".$db.".place='".$place."'";
	}
	if($thefind!="")
	{
		$sql2=$sql2."and (".$db.".type like '%".$thefind."%' or ".$db.".description like '%".$thefind."%' or ".$db.".lostname like '%".$thefind."%')";

		
	}
	$sql="select ".$db.".fname,".$db.".lostname,".$db.".id,".$db.".place,".$db.".time ,user_message.name from ".$db." inner join user_message on ".$db.".user_id=user_message.id ".$sql2." order by ".$db.".id desc limit ".$limst.",9";
}
	$data=$this->db->query($sql);
	$db=$data->result_array($data);
	return $db;
}
表结构



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值