PHP 从数据库遍历返回json

<?php session_start(); include("conn/conn.php");?>
<?php
	//Pick out information from database and print out.
	$type = $_GET['type'];
	$q_word="select id ,attr_type,pic_url,pic_desc from projectinfo where attr_type='".$type."' order by attr_type";
	$res=mysql_query($q_word);
	if ($res){
	while($row=mysql_fetch_array($res)){
	 // echo $site.'/'.$upload_dir.'/'.$p_name.'/'.$row[attr_type].'/'.$row[pic_url]; 
	 $json=json_encode($row);
      echo $json;
	  }
	}else{
		echo "无记录!";
	}
	
?>

posted @ 2012-07-01 11:55  sfshine  阅读(612)  评论(0编辑  收藏  举报