php获取数据列表 php获取数据类型

php联动下拉菜单,动态获取数据库及数据库的所有表比如你有一个城市表
city,有字段id和city_name,
代码如下:
?php
$sql
=
'select
*
from
city';
$res
=
mysql_query($sql);
$cities
=
array();
while
($row
=
mysql_fetch_assoc($res)
)
{
$cities[$row['id']]
=
$row['name'];
}
?
--
请选择城市
--
?php
foreach
(
$cities
as
$id=
$city
)
{
?
?php
echo
$city;
?
原理就是从mysql查询出所有城市的数据并弄成一个数组$cities
,然后循环$cities,按照下拉表单的格式输出option选项就好了
PHP怎么获取表单提交的数据?。?/h2>一、用file_get_contents以get方式获取内容,需要输入内容为:
1、?php
2、$url='';
3、$html=file_get_contents($url);
4、echo$html;
5、?
二、用file_get_contents函数,以post方式获取url,需要输入内容为
1、?php
2、$url='';
3、$data=https://www.04ip.com/post/array('foo'='bar');
4、$data=https://www.04ip.com/post/http_build_query($data);
5、$opts=array(
6、'http'=array(
7、 'method'='POST',
8、 'header'="Content-type:application/x-www-form-urlencoded\r\n".
9、"Content-Length:".strlen($data)."\r\n",
10、 'content'=$data
11、)
12、);
13、$ctx=stream_context_create($opts);
14、$html=@file_get_contents($url,'',$ctx);
15、?
三、用fopen打开url,以get方式获取内容,需要输入内容为
1、?php
2、$fp=fopen($url,'r');
3、$header=stream_get_meta_data($fp);//获取信息
4、while(!feof($fp)){
5、$result.=fgets($fp,1024);
6、}
7、echo"urlheader:{$header}br":
8、echo"urlbody:$result";
9、fclose($fp);
10、?
四、用fopen打开url,以post方式获取内容,需要输入内容为
1、?php
2、$data=https://www.04ip.com/post/array('foo2'='bar2','foo3'='bar3');
3、$data=https://www.04ip.com/post/http_build_query($data);
4、$opts=array(
5、'http'=array(
6、'method'='POST',
7、'header'="Content-type:application/x-www-form-urlencoded\r\nCookie:cook1=c3;cook2=c4\r\n".
8、"Content-Length:".strlen($data)."\r\n",
9、'content'=$data
10、)
11、);
12、$context=stream_context_create($opts);
13、$html=fopen(';id2=i4','rb',false,$context);
14、$w=fread($html,1024);
15、echo$w;
16、?
五、用fsockopen函数打开url,以get方式获取完整的数据,包括header和body,需要输入内容为
1、?php
2、functionget_url($url,$cookie=false)
3、{
4、$url=parse_url($url);
5、$query=$url[path]."?".$url[query];
6、echo"Query:".$query;
7、$fp=fsockopen($url[host],$url[port]?$url[port]:80,$errno,$errstr,30);
8、if(!$fp){
9、returnfalse;
10、}else{
11、$request="GET$queryHTTP/1.1\r\n";
12、$request.="Host:$url[host]\r\n";
13、$request.="Connection:Close\r\n";
14、if($cookie)$request.="Cookie:$cookie\n";
15、$request.="\r\n";
16、fwrite($fp,$request);
17、while(!@feof($fp)){
18、$result.=@fgets($fp,1024);
19、}
20、fclose($fp);
21、return$result;
22、}
23、}
24、//获取url的html部分,去掉header
25、functionGetUrlHTML($url,$cookie=false)
26、{
27、$rowdata=https://www.04ip.com/post/get_url($url,$cookie);
28、if($rowdata)
29、{
【php获取数据列表 php获取数据类型】30、$body=stristr($rowdata,"\r\n\r\n");
31、$body=substr($body,4,strlen($body));
32、return$body;
33、}
34、 returnfalse;
35、}
36、?
参考资料:
php-file_get_contents
如何用php取出数据库表中一列所有数据?很简单,用循环 , 你那样用只能有一条记录,建议多看看php手册,对自己有好处
while ($result= mysql_fetch_array($result, MYSQL_NUM)) {
print_r($result);
}
php获取mysql数据库里面的所有数据表信息没这么干过mysql_list_tables获取 所有表信息返回指针mysql_tablename获取表名
myslq_num_rows函数来判断结果指针中php获取数据列表的表的数目
?php
mysql_connect("localhost", "mysql_user", "mysql_password");
$result = mysql_list_tables("mydb");
for ($i = 0; $imysql_num_rows($result); $i)
printf ("Table: %s\n", mysql_tablename($result, $i));
mysql_free_result($result);
?这是手册上例子后边的不用php获取数据列表我说了吧sql查询
如何用php取出数据库表中一列所有数据用该列的字段名即可,select语句的通用形式如下:
select 你要的信息
from 数据表(一个或多个)
where 满足的条件
所以你的sql语句为:
select 要取得列名 from 表名 where 1
例子
SELECT id FROM `article` where 1
php获取数据列表的介绍就聊到这里吧,感谢你花时间阅读本站内容 , 更多关于php获取数据类型、php获取数据列表的信息别忘了在本站进行查找喔 。

    推荐阅读