如何使用单独的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. 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.