I have to show a vast list of data from mysqli database ,but when I'm trying to show the data only the first item is showing in the table(here multiple data is coming for single id and there are around 16,000 id,like for one id i.e site thier is door alarm,site alarm,battery alarm and fault alarm). I have tried while loop but it's not working here.
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>";
?>
CodePudding user response:
If you want all your item to show then you need to use a while loop instead of if Because while loop will loop through it all. try it and if doesn't work then drop the issue here. I will reply
CodePudding user response:
It's only showing 1 item because you only do 1 mysql_fetch_row($result). Maybe try this
while($data = mysql_fetch_row($result)) {
//The code you have after to generate the table
}
Documentation: https://www.php.net/manual/en/function.mysql-fetch-row.php