ฉันต้องแสดงรายการข้อมูลจำนวนมากจากฐานข้อมูล mysqli แต่เมื่อฉันพยายามแสดงข้อมูล เฉพาะรายการแรกเท่านั้นที่แสดงในตาราง (ที่นี่มีหลายข้อมูลสำหรับ id เดียว และมีประมาณ 16,000 รายการ id เช่นสำหรับ id เดียวคือไซต์ของพวกเขาคือสัญญาณเตือนประตู, สัญญาณเตือนไซต์, สัญญาณเตือนแบตเตอรี่และสัญญาณเตือนข้อผิดพลาด) ฉันได้ลองแล้วในขณะที่วนซ้ำ แต่มันไม่ทำงานที่นี่
code
<?php
ก่อน>
include \'dbinc.php\';
mysql_connect($mysql_hostname,$mysql_user,$mysql_password);//database connection
mysql_select_db($mysql_database);
$order = "SELECT * FROM quanta
ORDER BY ID DESC
LIMIT 1
";
//order to search data
//declare in the order variable
$result = mysql_query($order);
//order executes the result is saved
//in the variable of $result
$data = mysql_fetch_row($result);
$data_id = $data[0]; //Unique Id
$data_timestamp = $data[1]; //Time Stamp by Server
$data_validated = $data[2]; //Validated by Server
$data_type = $data[3]; //Type 0 - Periodic / 1 - Fault
$data_type_str = "Unknown";
if ($data[3] == 0) $data_type_str = "Periodic";
if ($data[3] == 1) $data_type_str = "Fault";
$data_site_id = $data[4]; //String Site Id
$data_datetime = $data[5]; //Date Time by Device
$data_device_id = $data[6]; //Device Id/ Only 1 known for now
$data_status = $data[7]; //Status Bits - To Expand
$data_status_hex= bin2hex($data_status);
$data_raw = $data[8]; //Raw Data, for device specific information
echo ("<table class=\'table table-striped\'>");
echo("
<tr><td>Site Id</td><td>$data[4]</td></tr>
<tr><td>Date Time</td><td>$data_datetime</td></tr>
<tr><td>Device Id</td><td>$data_device_id</td></tr>");
//echo ("Status: <b>$data_status</b><br>");
//echo ("Status: <b>$data_status_hex</b></tr>");
//$tmp = gettype($data_status);
//echo "Var: $tmp<br>";
$stats = unpack ( "C*" , $data_status );
//var_dump($stats);
//for table
echo "<tr><td>Smoke Fire Alarm</td><td";
//0x0000000000 Smoke fire 0 means No alarm, 1 means Alarm
if (($stats[5] & 0x01) == false)
echo " >no Smoke alarm";
else
echo " >smoke alarm";
echo "</td></tr>" ;
echo "<tr><td>Door</td><td";
//$FLAG_01_DOOR = 0x0000000002; //Door Open 0 means Door Close , 1 Means Door open
if (($stats[5] & 0x02) == false)
echo " >door closed";
else
echo " >door open";
echo "</td></tr>";
echo "<tr><td>Mode</td><td";
//$FLAG_02_AUTO = 0x0000000004; //Auto/Man Mode 0 Means Auto Mode, 1 Means Man Mode
if (($stats[5] & 0x04) == false)
echo " >Auto";
else
echo " >Manual";
echo "</td></tr>";
echo "<tr><td>Load</td><td>";
//$FLAG_034_LOAD = 0x0000000018; //00 :Load on EB,01: Load on DG, 10: Load on site Battery 11: Not used
if (($stats[5] & 0x08) == false)
{
if (($stats[5] & 0x10) == false)
echo "[- Load on EB -]<br>"; //00
else
echo "[- Load on site Battery -]<br>"; //10
}
else
{
if (($stats[5] & 0x10) == false)
echo "[- Load on DG -]<br>"; //01
else
echo "[- Not Used -]<br>"; //11
}
echo "</td></tr>";
echo "<tr><td>Alternate Fault</td><td";
//$FLAG_10_ALT = 0x0000000400; //Alternate Fault
if (($stats[4] & 0x04) == false)
echo " >no fault";
else
echo " >fault";
echo "</td></tr>";
?>
แสดงเพียง 1 รายการเนื่องจากคุณทำ 1 mysql_fetch_row($result)
อาจลองวิธีนี้
{-code -1}
เอกสาร: https://www.php.net/manual/en/function.mysql-fetch-row.php
ถ้าคุณต้องการให้รายการทั้งหมดของคุณแสดง คุณต้องใช้การวนรอบ while
while($data = mysql_fetch_row($result)){< /p>
//ป้อนรหัสของคุณที่นี่
}
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
DBMS is a database management system. It is designed to change, search, add and delete information in the database. There are many DBMSs designed for similar purposes with different features. One of the most popular is MySQL.
It is a software tool designed to work with relational SQL databases. It is easy to learn even for site owners who are not professional programmers or administrators. MySQL DBMS also allows you to export and import data, which is convenient when moving large amounts of information.
https://www.mysql.com/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.