新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

php记录获取数据 php获取表单数据

php如何获取数据库信息

代码如下:?View

成都创新互联公司提供高防主机、云服务器、香港服务器、绵阳服务器托管

Code

PHP

include("conn.php");//调用数据库连接文件

echo

"table

width=572

height=56

border=0

cellspacing=1

";

//创建html表格

echo

"tr

bgcolor=#9999FF";

echo

"th

width=33

scope=colid/th";

echo

"th

width=100

scope=coluser_name/th

";

echo

"th

width=100

scope=coluser_pass/th

";

echo

"th

width=100

scope=colstaus/th";

echo

"th

width=100

scope=colinsert_time/th";

echo

"/tr";

$SQL

=

"select

*

from

user_info";

$query

=

mysql_query($SQL);

//SQL查询语句

while

($row

=

mysql_fetch_array($query)){

//使用while循环mysql_fetch_array()并将数据返回数组

echo

"tr

onmouseout=this.style.backgroundColor=''

onMouseOver=this.style.backgroundColor='#99CC33'

bgcolor=#CCCCCC";

echo

"td$row[0]/td";

//输出数组中数据

echo

"td$row[1]/td";

echo

"td$row[2]/td";

echo

"td$row[3]/td";

echo

"td$row[4]/td";

echo

"/tr";

}

echo

"/table";输出记录截图

php获取post数据

方法1、最常见的方法是:$_post['fieldname'];

说明:只能接收content-type:

application/x-www-form-urlencoded提交的数据

解释:也就是表单post过来的数据

方法2、file_get_contents("php://input");

说明:

允许读取

post

的原始数据。

$http_raw_post_data

比起来,它给内存带来的压力较小,并且不需要任何特殊的

php.ini

设置。

php://input

不能用于

enctype="multipart/form-data"。

解释:

对于未指定

content-type

的post数据,则可以使用file_get_contents(“php://input”);来获取原始数据。

事实上,用php接收post的任何数据都可以使用本方法。而不用考虑content-type,包括二进制文件流也可以。

所以用方法二是最保险的方法

方法3、$globals['http_raw_post_data'];

说明:

总是产生

$http_raw_post_data

变量包含有原始的

post

数据。

此变量仅在碰到未识别

mime

类型的数据时产生。

$http_raw_post_data

对于

enctype="multipart/form-data"

表单数据不可用

如果post过来的数据不是php能够识别的,可以用

$globals['http_raw_post_data']来接收,

比如

text/xml

或者

soap

等等

解释:

$globals['http_raw_post_data']存放的是post过来的原始数据。

$_post或$_request存放的是

php以key=value的形式格式化以后的数据。

但$globals['http_raw_post_data']中是否保存post过来的数据取决于centent-type的设置,即post数据时

必须显式示指明content-type:

application/x-www-form-urlencoded,post的数据才会存放到

$globals['http_raw_post_data']中

怎样利用php获取数据库中指定的记录

这是PHP获取数据库信息的代码 希望能给你带来启发

?php

$conn=mysql_connect("localhost","root","");

$select=mysql_select_db("books",$conn);

$query="insert into computers(name,price,publish_data) ";

$query.="values('JSP',28.00,'2008-11-1')";

$query="select * from computers";

$result=mysql_query($query);

//以下是使用mysql_result()函数来获取到查询结果

$num=mysql_num_rows($result);

for($rows_count=0;$rows_count$num;$rows_count++){

echo "书名:".mysql_result($result,$rows_count,"name");

echo "价格:".mysql_result($result,$rows_count,"price");

echo "出版日期:".mysql_result($result,$rows_count,"publish_data")."br";

}

//以下是使用mysql_fetch_row()函数来获取到查询结果

while($row=mysql_fetch_row($result))

{

echo "书号:".$row[0]."br";

echo "书名:".$row[1]."br";

echo "价格:".$row[2]."br";

echo "出版日期:".$row[3]."br";

echo "br";

}

//以下是使用mysql_fetch_array()函数来获取到查询结果

while($row=mysql_fetch_array($result))

{

echo "书号:".$row[0]."br";

echo "书名:".$row[1]."br";

echo "价格:".$row["price"]."br";

echo "出版日期:".$row["publish_data"]."br";

echo "br";

}

//以下是使用mysql_fetch_object()函数来获取到查询结果

while($row=mysql_fetch_object($result))

{

echo "书号:".$row-id."br";

echo "书名:".$row-name."br";

echo "价格:".$row-price."br";

echo "出版日期:".$row-publish_data."br";

echo "br";

}

?

如何在PHP中获取MYSQL数据库返回的数据的行数?

1、首先打开MYSQL的管理工具,新建一个test表,并且在表中插入两个字段。

2、接下来在Editplus编辑器中创建一个PHP文件,然后进行数据库连接,并且选择要操作的数据库。

3、然后通过mysql_query方法执行一个Insert的插入语句。

4、执行完毕以后,我们回到数据库管理工具中,这个时候你会发现插入的中文乱码了。

5、接下来我们在PHP文件中通过mysql_query执行一个set  names  utf8语句即可完成操作。

php如何获取数据库里上一周的数据?

你的数据库里需要有一个记录时间的字段,例如这个字段是posttime,每次插入数据的时候,都记录下当前的时间戳,也就是time();

你需要得到上周开始,和上周结束的时间戳

$beginLastweek=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));

$endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));

3.查询的时候,WHERE 条件里加上  posttime=$beginLastweek AND posttime=$endLastweek 

希望对你有帮助

如何正确理解PHP获取显示数据库数据函数

1、PHP获取显示数据库数据函数之 mysql_result()

mixed mysql_result(resource result_set, int row [,mixed field])

从result_set 的指定row 中获取一个field 的数据. 简单但是效率低.

举例:

$link1 = @mysql_connect("server1", 

"webuser", "password") 

or die("Could not connect 

to mysql server!");

@mysql_select_db("company") 

or die("Could not select database!");

$query = "select id, name 

from product order by name"; 

$result = mysql_query($query);

$id = mysql_result($result, 0, "id");

$name = mysql_result($result, 0, "name");

mysql_close();

注意,上述代码只是输出结果集中的第一条数据的字段值,如果要输出所有记录,需要循环处理.

for ($i = 0; $i = mysql_num_rows($result); $i++)

{

$id = mysql_result($result, 0, "id");

$name = mysql_result($result, 0, "name");

echo "Product: $name ($id)";

}

注意,如果查询字段名是别名,则mysql_result中就使用别名.

2、PHP获取显示数据库数据函数之mysql_fetch_row()

array mysql_fetch_row(resource result_set)

从result_set中获取整行,把数据放入数组中.

举例(注意和list 的巧妙配合):

$query = "select id, 

name from product order by name"; 

$result = mysql_query($query);

while(list($id, $name) 

= mysql_fetch_row($result)) {

echo "Product: $name ($id)";

}

3、PHP获取显示数据库数据函数之mysql_fetch_array()

array mysql_fetch_array(resource result_set [,int result_type])

mysql_fetch_row()的增强版.

将result_set的每一行获取为一个关联数组或/和数值索引数组.

默认获取两种数组,result_type可以设置:

MYSQL_ASSOC:返回关联数组,字段名=字段值 

MYSQL_NUM:返回数值索引数组.

MYSQL_BOTH:获取两种数组.因此每个字段可以按索引偏移引用,也可以按字段名引用.

举例:

$query = "select id,

name from product order by name";

$result = mysql_query($query);

while($row = mysql_fetch_array

($result, MYSQL_BOTH)) { 

$name = $row['name'];

//或者 $name = $row[1];

$name = $row['id'];

//或者 $name = $row[0];

echo "Product: $name ($id)";

}

4、PHP获取显示数据库数据函数之mysql_fetch_assoc()

array mysql_fetch_assoc(resource result_set)

相当于 mysql_fetch_array($result, MYSQL_ASSOC)

5、PHP获取显示数据库数据函数之mysql_fetch_object()

object mysql_fetch_object(resource result_set) 

和mysql_fetch_array()功能一样,不过返回的不是数组,而是一个对象.

举例:

$query = "select id, name 

from product order by name";

$result = mysql_query($query); 

while($row = mysql_fetch_object

($result)) {

$name = $row-name;

$name = $row-id;

echo "Product: $name ($id)";

}

以上这些函数就是PHP获取显示数据库数据函数的全部总结。


当前名称:php记录获取数据 php获取表单数据
网页网址:http://www.wjwzjz.com/article/hgjjie.html
在线咨询
服务热线
服务热线:028-86922220
TOP