查詢phpMyAdmin資料表資料

<?php

$mysqli = new mysqli('localhost', 'root', '20190129app', 'app_record');
//require"conn.php";
mysqli_set_charset($mysqli, "UTF8");

//$sql = "SELECT * FROM location ORDER BY id ASC LIMIT 1";//取第一行
$sql = "SELECT * FROM location ORDER BY id DESC LIMIT 1";//取最後一行


if (!$result = $mysqli->query($sql)) {
    // Oh no! The query failed.
    echo "Sorry, the website is experiencing problems.";

    // Again, do not do this on a public site, but we'll show you how
    // to get the error information
    echo "Error: Our query failed to execute and here is why: \n";
    echo "Query: " . $sql . "\n";
    echo "Errno: " . $mysqli->errno . "\n";
    echo "Error: " . $mysqli->error . "\n";
    exit;
}


if ($result->num_rows === 0) {
    // Oh, no rows! Sometimes that's expected and okay, sometimes
    // it is not. You decide. In this case, maybe actor_id was too
    // large?
    echo "We could not find any data, sorry about that. Please try again.";
    exit;
}

$row = $result->fetch_assoc();


echo '<table border="0" cellspacing="2" cellpadding="2">
      <tr>
          <td> <font face="Arial">username</font> </td>
          <td> <font face="Arial">userid</font> </td>
          <td> <font face="Arial">longitude</font> </td>
          <td> <font face="Arial">latitude</font> </td>
          <td> <font face="Arial">date</font> </td>
          <td> <font face="Arial">time</font> </td>
          <td> <font face="Arial">m_code</font> </td>
          <td> <font face="Arial">ap_ip</font> </td>
          <td> <font face="Arial">ap_ssid</font> </td>
          <td> <font face="Arial">ap_rssi</font> </td>
      </tr>';
        $field1name = $row['username'];
        $field2name = $row["userid"];
        $field3name = $row["longitude"];
        $field4name = $row["latitude"];
        $field5name = $row["date"];
        $field6name = $row['time'];
        $field7name = $row['m_code'];
        $field8name = $row['ap_ip'];
        $field9name = $row['ap_ssid'];
        $field10name = $row['ap_rssi'];
echo '<tr>
                  <td>'.$field1name.'</td>
                  <td>'.$field2name.'</td>
                  <td>'.$field3name.'</td>
                  <td>'.$field4name.'</td>
                  <td>'.$field5name.'</td>
                  <td>'.$field6name.'</td>
                  <td>'.$field7name.'</td>
                  <td>'.$field8name.'</td>
                  <td>'.$field9name.'</td>
                  <td>'.$field10name.'</td>
              </tr>';



//echo "今天是 " . date("Y-m-d") . "<br>";
//echo "今天是 " . date("l");//星期幾
date_default_timezone_set("Asia/Shanghai");
echo "目前時間為 " . (int)date("H"). ":". (int)date("i"). "<br>";


?>

留言