How to do it...

  1. Create the following PHP files and save them in the web server directory named /var/www/./.
  2. Use the following command to create the PHP file:
sudo nano /var/www/show_data_lite.php
  
  1. The show_data_lite.php file should contain the following:
<head> 
<title>DatabaseDatabase Data</title> 
<meta http-equiv="refresh" content="10" > 
</head> 
<body> 
 
Press button to remove the table data 
<br> 
<input type="button" onclick="location.href = 'del_data_lite.php';" value="Delete"> 
<br><br> 
<b>Recorded Data</b><br> 
<?php 
$db = new PDO("sqlite:/var/databases/datasitedatasite/mydatabase.db"); 
//SQL query 
$strSQL = "SELECT * FROM recordeddatarecordeddata WHERE itmitm_name LIKE '%'%temp%'"; 
//Execute the query 
$response = $db->query($strSQL); 
//Loop through the response 
while($column = $response->fetch()) 
{ 
   //Display the content of the response 
   echo $column[0] . " "; 
   echo $column[1] . " "; 
   echo $column[2] . " "; 
   echo $column[3] . "<br />"; 
} 
?> 
Done 
</body> 
</html>
  1. Use the following command to create the PHP file:
sudo nano /var/www/del_data_lite.php
<html>
<body>
    
Remove all the data in the table.
<br>
<?php
$db = new PDO("sqlite:/var/databases/datasitedatasite/mydatabase.db");
//SQL query
$strSQL = "DROPDROP TABLErecordeddata recordeddata";
//ExecuteExecute the query
$response = $db->query($strSQL);

if ($response == 1)
    {
      echo "Result: DELETED DATA";
    }
else
    {
      echo "Error: Ensure table exists and database directory is owned    
by www-data";
} ?> <br><br> Press button to return to data display. <br> <input type="button" onclick="location.href = 'show'show_data_lite.php';" value="Return"> </body> </html>
In order for the PHP code to delete the table within the database, it needs to be writable by the web server. Use the following command to allow it to be writable:

  sudo chown www-data /var/databases/datasite -R
  1. The show_data_lite.php file will appear as a web page if you open it in a web browser by using the following address:
http://localhost/showshow_data_lite.php
  1. Alternatively, you can open the web page (on another computer within your network, if you wish) by referencing the IP address of the Raspberry Pi (use hostname -I to confirm the IP address):
http://192.168.1.101/showshow_data_lite.php 

You may be able to use the hostname instead (by default, this would make the address http://raspberrypi/show_data_lite.php). However, this may depend upon your network setup.

If there is no data present, ensure that you run the mysqlite_adc.py script to capture additional data.

  1. To make the show_data_lite.php page display automatically when you visit the web address of your Raspberry Pi (instead of the It works! page), we can change the index.html to the following:
<meta http-equiv="refresh" content="0; URL='show_data_lite.php' " /> 

This will automatically redirect the browser to load our show_data_lite.php page.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.249.174