jump display

查找了数据库,再在while里拼接成json是很麻烦的,所以,jump display

获得数组

<?php

header("Content-Type:text/html; charset=utf-8");

/*json接口测试*/
$g=$_GET['g'];
$v=$_GET['v'];
$msu=$_GET['msu'];
print_r ($g);
print_r ($v);
print_r ($msu);
/*json*接口测试*/



//进行my数据库连接
$con = mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_query("set names utf8");//ut8声明
mysql_select_db("examples", $con);//打开my里的数据库

//显示my里的用户数据以便于添加参照
$my = mysql_query("SELECT name FROM `think_form` WHERE city = '上海' AND groupName = '专家'");


echo "[";
while($a=mysql_fetch_array($my))
  {
echo json_encode($a['name']).",";
}
echo "]";

?>

再次修改显示内容,还可以做个伪接口

<?php 
//get传值
header("Content-Type:text/html; charset=utf-8");
$g=$_GET['g'];
$urlg = "http://localhost/a.php?g=".$g ; 
$contentsg = file_get_contents($urlg); 
//如果出现中文乱码使用下面代码 
//$getcontent = iconv("gb2312", "utf-8",$contentsg); 
echo preg_replace('(,])',']',$contentsg);//preg_replace(find,被替换成,字符串)
echo "<br>";
?> 

接口本来要传很多的参数,但是天晚了,想的费功夫,多写几个伪接口页面就得了。。。

原文地址:https://www.cnblogs.com/hellowzd/p/4163825.html