很多站长朋友们都不太清楚php获取数据数目,今天小编就来给大家整理php获取数据数目,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 php 怎么获取用户在数据库的所有数据 2、 PHP怎么在数据库取出指定数量的值? 3、 php使用mysql怎么查询数据库已经有多少条数据 4、 PHP怎么获取表单提交的数据啊? 5、 php如何获取几行数据 php 怎么获取用户在数据库的所有数据首先你的数据表中得有这个用户的唯一标识,如用户id=1。
根据用户id查询所有匹配的数据。
SELECT * FROM `数据表` WHERE ( id=1 );
PHP怎么在数据库取出指定数量的值?count(*)是统计满足这个查询条件的所有记录的总数
是一个数值,你用limit 30 当然没有效果啦
因为查出来的肯定就一条记录
你可以再数据库里执行一下 select count(*) from dx_queue
假设总共有100条记录显示的结果是
count(*)
100
limit是不起作用的。。
明白么。。
php使用mysql怎么查询数据库已经有多少条数据php使用mysql查询数据库已经有多少条数据使用sql的count函数实现。
示例代码如下:
<?php
//数据库连接
$conn=mysql_connect("localhost","root","root");
if(!$conn){
die("对不起,数据库连接失败! ").mysql_errno();
}
//选择数据库
mysql_select_db("testdb");
//sql语句
$sql="SELECT COUNT(*) AS count FROM user";
//执行sql
$query=mysql_query($sql,$conn);
//对结果进行判断
if(mysql_num_rows( $query)){
$rs=mysql_fetch_array($query);
//统计结果
$count=$rs[0];
}else{
$count=0;
}
echo $count;
?>
返回的$count就是当前数据库的记录条数。
PHP怎么获取表单提交的数据啊?一、用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=array('foo'=>'bar');
4、$data=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=array('foo2'=>'bar2','foo3'=>'bar3');
3、$data=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=get_url($url,$cookie);
28、if($rowdata)
29、{
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 读取数据一般都是在循环读取的时候把数据放入数组里,例如
<?php
$link = mysql_connect("数据库地址","用户名","密码");//连接服务器
mysql_select_db("数据库名",$link);//连接数据库
mysql_query("set names gb2312");//设置字符集
$str = "select * from table1";//查询语句
$result = mysql_query($str,$link);//执行查询
$re_array = new array();//构造数组
while($row = mysql_fetch_array($result))
{
$re_array[] = $row['列名'];//这样可以保存多列数据,根据语句不同,需要在这进行相应修改
}
?>
关于php获取数据数目的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于php获取数据数目 php获取数据库的详细内容...