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="";
        var a1s=document.getElementsByClassName("dark");
                // document.getElementById("dark1").innerHTML=""+res[0].name+"同学
于"+res[0].time+res[0].place+"
丢失"+res[0].lostname+""; for(var i=0;i于"+res[i].place+"
丢失"+res[i].lostname+""; 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="暂无更多信息"; 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;
}
表结构



你可能感兴趣的:(codeigniter---json解析)