Maison > php教程 > PHP源码 > PHP连接数据库,点击按钮查询数据,没点击的时候,如果有数据,那么按钮变红,没有数据则不变红。

PHP连接数据库,点击按钮查询数据,没点击的时候,如果有数据,那么按钮变红,没有数据则不变红。

PHP中文网
Libérer: 2016-05-25 16:58:09
original
1700 Les gens l'ont consulté

代码

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

<html>

<body>

<?php

echo "<input type=&#39;button&#39; id=&#39;anniu&#39; style=&#39;width:250px;height:25px;font-weight:bold;font-size:14px&#39; onclick=\"window.location=&#39;demo1.php&#39;\" value=&#39;查询逾期无吨位车辆信息&#39; />";

echo "<input type=&#39;button&#39; style=&#39;width:250px;height:25px;font-weight:bold;font-size:14px&#39;onclick=\"window.location=&#39;huizong.php&#39;\" value=&#39;查询汇总信息&#39; />";

    $mysql_server_name="localhost"; //数据库服务器名称

    $mysql_username="root"; // 连接数据库用户名

    $mysql_password="123456"; // 连接数据库密码

    $mysql_database="td_oa"; // 数据库的名字

     

    // 连接到数据库

    $conn=mysql_connect($mysql_server_name, $mysql_username,

                        $mysql_password);

//解决乱码

mysql_query("SET NAMES &#39;UTF8&#39;");

mysql_query("SET CHARACTER SET UTF8");

        mysql_query("SET CHARACTER_SET_RESULTS=UTF8&#39;");

                         

     // 从表中提取信息的sql语句

$strsql="select a.field4 as &#39;车号&#39;,a.field8 as&#39;任务号&#39;,a.field5 as&#39;装货日期&#39; ,a.field6 as&#39;供应商名称&#39;,a.field7 as&#39;采购价格&#39; from `crm_storage` a left join `crm_order` b on a.field4=b.field2 and a.field8=b.field16

where (b.field8=0 or b.field8 is null)

and DATE_ADD(a.field5,INTERVAL 4 day)<CURDATE()";

    // 执行sql查询

    $result=mysql_db_query($mysql_database, $strsql, $conn);

    // 获取查询结果

    $row=mysql_fetch_row($result);

//没有查询结果则让$have=0;有查询结果$have=1;然后后面的JS根据$have的值来处理按钮变色

if(empty($row)){

$have=0;

}else{

$have=1;

}

?>

<script type="text/javascript">

window.onload=function()

{

have=<?php echo $have;?>;

if(have>0){

document.getElementById("anniu").style.backgroundColor="red";

}

}

</script>

</body>

</html>

Copier après la connexion
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Recommandations populaires
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal