需要准备的材料分别是:电脑、php编辑器、浏览器。
1、首先,打开php编辑器,新建php文件,例如:indexphp,填充问题基础代码。
2、在indexphp中,输入代码:
$b = json_decode($a);
echo $b->content->location->lat;
echo ',';
echo $b->content->location->lng;
3、浏览器运行indexphp页面,此时lng和lat的值都被打印了出来。
sql='select from table';
while(res=mysql_fetch_assoc(sql)){
echo "res['name']<br>"
}
恩,就是以上代码就可以啦,那个TABLE改成你要的那张表就可以了!希望可以帮到你!
我直接在这给你修改答案算了
使用的时候删除行号 修改数据库配置 如果想使用 页面不刷新查询数据库 需要使用JQUERY 如果有需要给我留言
1 <php
2 if(isset($_POST['submit'])&&$_POST['submit']=='提交'){
3 //判断是否是提交过来的
4 $intext = $_POST['intext'];
5 if($intext!=null||$intext!=''){
6 $link = mysql_connect("localhost", "root", "123456");
7 //数据库配置信息 第一个参数数据库位置第二个是用户名第三个是密码
8 mysql_select_db("szn_test");
9 //设置要使用的数据库
10 $sql = "select from demo where res = '"$intext"'";
11 //SQL语句
12 var_dump($sql);
13 $res = mysql_query($sql);
14 $arr = array();
15 //吧结果存入数组 并记录数组长度
16 $count = 0;
17 while($data = mysql_fetch_array($res)){
18 $arr[$count] = $data;
19 $count++;
20 }
21 //关闭数据库
22 mysql_close($link);
23 }
24 }
25
26 >
27 <html>
28 <head>
29 <title></title>
30 </head>
31 <body>
32 <form id="form1" method="post" action="demophp">
33 <input type="text" name="intext">
34 <input type="submit" name="submit" value="提交">
35 </form>
36 <php
37 if(isset($arr)&&$arr != null){
38 for($i = 0; $i < $count; $i++){
39 foreach($arr[$i] as $key => $value){
40 echo "key:"$key" value:"$value;
41 echo " ";
42 }
43 echo "<br>";
44 }
45 }
46 >
47 </body>
48 </html>
这个是数据库查询代码 你可以看以下对照着修改修改
$link = mysql_connect('localhost', '数据库用户', '数据库密码');
$db_list = mysql_list_dbs($link);
while ($row = mysql_fetch_object($db_list)) {
$dbname = $row->Database;//得到数据库名
break;
}
$result = mysql_list_tables($dbname);
while ($row = mysql_fetch_row($result)) {
$Table=$row[0];break;//得到表名
}
mysql_free_result($result);
$db=mysql_select_db($dbname,$link); //选择目标数据库名
$query=mysql_query("select from {$Table} limit 0,1"); //查询1条记录
$r=mysql_fetch_array($query); //将查询结果的值赋给$r
print_r($r); //一条数据
以上就是关于请教php大神,如何提取一个json数据里的某值全部的内容,包括:请教php大神,如何提取一个json数据里的某值、PHP怎么实现按id从my SQL数据库表中读取一条内容、用PHP代码如何查询数据库表中的一条记录等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)