|
|
|
สอบถามการเขียน code แบ่งค่าใส่ในตารางแล้วทำการ check สถานะแต่ละช่อง |
|
|
|
|
|
|
|
ใช้โค้ดวนลูปเพื่อสร้างตาราง และในลูปก็ทำการคิวรี่จากฐานข้อมูล เพื่อตรวจดูสถานะว่าเท่ากับ 2 มั๊ย
ถ้าใช่ก็แสดง X
แค่นั้นล่ะครับ
|
|
|
|
|
Date :
2015-02-01 19:21:57 |
By :
ไม่ทราบแหล่งที่มา |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
พอมี code แนะนำมั้ยอ่าครับ พอดีผม มือใหม่ เลยยังนึก ไม่ออกครับ ^^
|
|
|
|
|
Date :
2015-02-01 22:55:55 |
By :
mart |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เอาโค้ดวนลูปสร้างตารางมาลงก่อนซิครับ
|
|
|
|
|
Date :
2015-02-02 10:15:40 |
By :
ไม่ทราบแหล่งที่มา |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
นี่อ่าครับ ลองเขียน ตรง A1 แบบนั้น จะได้มั้ยอ่าครับ แต่มันก็ยังไม่ออกเลยครับ
Code (PHP)
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_connectrpi = "localhost";
$database_connectrpi = "db_rpi";
$username_connectrpi = "user";
$password_connectrpi = "password";
$connectrpi = mysql_pconnect($hostname_connectrpi, $username_connectrpi, $password_connectrpi) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_query("Set Names UTF8");
?>
<?php
mysql_select_db($database_connectrpi, $connectrpi);
$query_db_sensor = "SELECT * FROM sensor_add";
$db_sensor = mysql_query($query_db_sensor, $connectrpi) or die(mysql_error());
$row_db_sensor = mysql_fetch_assoc($db_sensor);
$totalRows_db_sensor = mysql_num_rows($db_sensor);
?>
<head>
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-image: url();
background-repeat: no-repeat;
background-position:center top;
}
-->
</style></head>
<body>
<table width="1050" height="1094" border="1" align="center">
<tr>
<td width="175" height="216"><?php
if ($db_sensor['class'] == "A1")
{
if ($db_sensor['status']=="2")
{echo "xxx";}
else
{echo "";}
}
?> <div align="center">A1 </div></td>
<td width="175" height="216"><div align="center">A2</div></td>
<td width="175" height="216"><div align="center">A3</div></td>
<td width="175" height="216"><div align="center">A4</div></td>
<td width="175" height="216"><div align="center">A5</div></td>
<td width="175" height="216"><div align="center">A6</div></td>
</tr>
<tr>
<td width="175" height="216"><div align="center">B1</div></td>
<td width="175" height="216"><div align="center">B2</div></td>
<td width="175" height="216"><div align="center">B3</div></td>
<td width="175" height="216"><div align="center">B4</div></td>
<td width="175" height="216"><div align="center">B5</div></td>
<td width="175" height="216"><div align="center">B6</div></td>
</tr>
<tr>
<td width="175" height="216"><div align="center">C1</div></td>
<td width="175" height="216"><div align="center">C2</div></td>
<td width="175" height="216"><div align="center">C3</div></td>
<td width="175" height="216"><div align="center">C4</div></td>
<td width="175" height="216"><div align="center">C5</div></td>
<td width="175" height="216"><div align="center">C6</div></td>
</tr>
<tr>
<td width="175" height="216"><div align="center">D1</div></td>
<td width="175" height="216"><div align="center">D2</div></td>
<td width="175" height="216"><div align="center">D3</div></td>
<td width="175" height="216"><div align="center">D4</div></td>
<td width="175" height="216"><div align="center">D5</div></td>
<td width="175" height="216"><div align="center">D6</div></td>
</tr>
<tr>
<td width="175" height="216"><div align="center">E1</div></td>
<td width="175" height="216"><div align="center">E2</div></td>
<td width="175" height="216"><div align="center">E3</div></td>
<td width="175" height="216"><div align="center">E4</div></td>
<td width="175" height="216"><div align="center">E5</div></td>
<td width="175" height="216"><div align="center">E6</div></td>
</tr>
</table>
</body>
</html><?php
mysql_free_result($db_sensor);
?>
|
|
|
|
|
Date :
2015-02-02 11:39:27 |
By :
mart |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_connectrpi = "localhost";
$database_connectrpi = "db_rpi";
$username_connectrpi = "user";
$password_connectrpi = "password";
$connectrpi = mysql_pconnect($hostname_connectrpi, $username_connectrpi, $password_connectrpi) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_query("Set Names UTF8");
?>
<?php
mysql_select_db($database_connectrpi, $connectrpi);
$query_db_sensor = "SELECT * FROM sensor_add";
$db_sensor = mysql_query($query_db_sensor, $connectrpi) or die(mysql_error());
$row_db_sensor = mysql_fetch_assoc($db_sensor);
$totalRows_db_sensor = mysql_num_rows($db_sensor);
?>
<head>
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-image: url();
background-repeat: no-repeat;
background-position:center top;
}
-->
</style></head>
<body>
<?php
$table = array(array('a1','a2','a3','a4','a5','a6'),array('b1','b2','b3','b4','b5','b6'), array('c1','c2','c3','c4','c5','c6'),array('d1','d2','d3','d4','d5','d6'),array('e1','e2','e3','e4','e5','e6'));
?>
<table width="1050" height="1094" border="1" align="center">
<?php
foreach($table as $row){
echo "<tr>";
foreach($row as $column){
echo "<td width='175' height='216'><div align='center'>".strtoupper($column)."</div>";
$result = mysql_query("select status from sensor_add where class='$column'") or die(mysql_error());
$sensor = mysql_fetch_assoc($result);
if($sensor["status"] >= 2)
echo "<div align='center'>X</div>";
else
echo "<div align='center'> </div>";
echo "</td>";
}
echo "</tr>";
}
?>
</table>
</body>
</html><?php
mysql_free_result($db_sensor);
?>
|
|
|
|
|
Date :
2015-02-02 13:23:59 |
By :
ไม่ทราบแหล่งที่มา |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากครับ ที่ช่วยดู code ให้ ^^
|
|
|
|
|
Date :
2015-02-02 19:46:07 |
By :
mart |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|