php数据库表记录 php查询数据库并输出表格

求助:在php中,怎么才能知道数据库(mysql)的表里面一共有多少条记录啊?

如果是客户端连接数据库的话,一条语句OK。select count(*) from tablename;

创新互联2013年开创至今,先为安源等服务建站,安源等地企业,进行企业商务咨询服务。为安源企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

?php

$conn=mysql_connect('localhost','root','password');//连接数据库

mysql_select_db('databasename',$conn);//选择要查询的数据库

$sql="select count(*) from tablename";//SQL查询语句

if($result=mysql_query($sql,$conn))

{

$aaa=mysql_fetch_row($result);

echo $aaa[0]; //输出表里面总记录数

}

php如何查询某个表一共多少条记录?

需要准备的材料分别是:电脑、php编辑器、浏览器。

1、首先,打开php编辑器,新建php文件,例如:index.php。

2、在index.php中,输入代码:

$conn = new mysqli('10.5.15.177', 'root', '', 'test');

$sql = "select * from stu";

$r = $conn-query($sql);

print_r($r-num_rows);

3、浏览器运行index.php页面,此时打印出了stu表的记录数是5。

用PHP代码如何查询数据库表中的一条记录

我直接在这给你修改答案算了

使用的时候删除行号

修改数据库配置

如果想使用

页面不刷新查询数据库

需要使用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="demo.php"

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

这个是数据库查询代码

你可以看以下对照着修改修改


新闻标题:php数据库表记录 php查询数据库并输出表格
本文来源:http://lszwz.com/article/hhhjss.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款