Example #1
0
function login()
{
    initDB($db, $username, $password);
    //$sql = "SELECT *  FROM `users` WHERE `account`= 'ryan';";
    $pwd = md5($_POST['pwd']);
    $sql = "SELECT *  FROM `users` WHERE `account`= '" . $_POST['account'] . "' AND `pwd` = '" . $pwd . "' AND `status` = '1' ;";
    // $sql = "SELECT *  FROM `users` ;";
    $result = mysql_query($sql) or die('MySQL query error');
    while ($row = mysql_fetch_assoc($result)) {
        $arr[] = $row;
    }
    // $arr = array('status' => true, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
    echo json_encode($arr);
    //print_r($arr);
    //mysql_close($database_link);
}
function getEnvironmentData()
{
    initDB($db, $username, $password);
    $sql = "SELECT * FROM `temperature`; ";
    $result = mysql_query($sql) or die('MySQL query error');
    while ($row = mysql_fetch_assoc($result)) {
        $arr[] = $row;
    }
    return json_encode($arr);
}
if ($_POST['act'] == "login") {
    login();
} elseif ($_POST['act'] == "getEnvironmentData") {
    getEnvironmentData();
}
Example #2
0
          <h2 class="sub-header">Section title</h2>
          <div class="table-responsive">
            <table class="table table-striped">
              <thead>
                <tr>
                  <th>id</th>
                  <th>value</th>
                  <th>T</th>
                  <th>D</th>

                </tr>
              </thead>
              <tbody>
              <?php 
$x = json_decode(getEnvironmentData());
//echo $x;
$i = 1;
foreach ($x as $value) {
    # code...
    if ($i++ > 10) {
        break;
    }
    ?>
<tr><th><?php 
    echo $value->id;
    ?>
</th><?php 
    ?>
<th><?php 
    echo $value->value;