dragonpeng200811111 2016-10-24 02:53
浏览 34

如何使用单独的php文件从MySQL数据库中检索一个值,并使用我从数据库中获取的值更改html控件?

How can I retrieve a one value from MySQL database using a seperate php file and change the html (which is also a separete file) control with the value I got from the database? * I am begginer in programming example html page

    <div class="container" style="padding:60px">
        <div class="row">
            <div class="col-md-1=12 col-xs-12">

<form method="post" action="SmartSwitch.php" >            
                <h1 align="center">SmartHome</h1>
                    <br> <hr>
                    <div align="center">
                        <B>Switches</B>
                        <P>Switch 1 - Level 1 , Room 1</P>

                        <p><b>Light :</b><br>

<!--I want to change this control for example <p>status</p> into ON-->
> <p><b>status :</b>

                        <input class="btn btn-primary btn-block" type="submit" value="   OFF   " name="submit1_L1" style="font-weight:bold;border:0px sloid white;border-radius:10px;"  >
                        </p>
                        <p>
                        <input onclick="ChangeText()" class="btn btn-primary btn-block" type="submit" value="    ON    " name="submit1_L2" style="font-weight:bold;border:0px sloid white;border-radius:10px;" >
                        </p>

                        <br>
                       <p><b>Air Condition :</b><br><input class="btn btn-primary btn-block" type="submit" value="   OFF   " name="submit1_C1" style="font-weight:bold;border:0px sloid                                 white;border-radius:10px;">
                       </p>

                     <p>
                       <input class="btn btn-primary btn-block" type="submit" value="   ON    " name="submit1_C2" style="font-weight:bold;border:0px sloid                              white;border-radius:10px;">
                       </p>

                        <br><span style="color:#F00"><hr></span>
                        <P>Switch 2 - Level 2 , Living Area</P>
                        <p><b>Light :</b><br><input class="btn btn-primary btn-block" type="submit" value="   OFF   " name="submit2_L1" style="font-weight:bold;border:0px sloid white;border-radius:10px;">
                        </p>

                        <p>
                        <input class="btn btn-primary btn-block" type="submit" value="   ON   " name="submit2_L2" style="font-weight:bold;border:0px sloid white;border-radius:10px;">
                        </p>



                         <br>
                       <p><b>Air Condition :</b><br><input class="btn btn-primary btn-block " type="submit" value="   OFF   " name="submit2_C1" style="font-weight:bold;border:0px sloid white;border-radius:10px;">
                       </p>

                       <p>
                       <input class="btn btn-primary btn-block" type="submit" value="   ON    " name="submit2_C2" style="font-weight:bold;border:0px sloid white;border-radius:10px;">
                       </p>



                        <br><br><hr>
                        <input class="btn btn-primary" type="submit" value="خـــــــــــــــروج" name="submit_Exit" style="font-weight:bold">
                    </div>


</form>

            </div>
        </div>
    </div>

and this is the php code

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SmartSwitch_P</title>
</head>

<body>
<?php


$con=mysqli_connect('localhost','root','root');

if(!$con)
{
    echo "Not connected";   
}

if (!mysqli_select_db($con,'smarthome'))
{
    echo "Database is not selected";    
}
//============== my select statement======================================
$sqlSELECT = "SELECT switch_status FROM smartswitch WHERE switch_no=1 AND device='Light' limit 1";** $result = mysqli_query($conn, $sqlSELECT); if (mysqli_num_rows($result) > 0) { { echo "Light 1 status is : " . $row["switch_status"]; } } else { echo "0 results"; } mysqli_close($conn);


?>

</body>
</html>

please help and thanks in advance ..>>>

  • 写回答

1条回答 默认 最新

  • dongzha2525 2016-10-27 08:23
    关注
    1. Use ajax in your html to contact php.
    2. php would pass back to ajax json data.
      Once you receive json data from php - it would be easy to iterate through it and add this data to html.

    Couple of links that might help
    1. http://api.jquery.com/jquery.ajax/
    2. http://php.net/manual/en/function.json-encode.php

    So basically you don't need to change html file. You will generate elements dynamically based on the output received from php.

    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)