Hi,

What i have is a variable that is getting updated periodically and i've set the php script to refresh itself every 30 seconds to run a mysql query updating a db, this is good but if this value isnt changing from the source i get duplicate records in the db, how do i check the value of the variable with php and only execute the query when the variable has changed value?

Thanks

Before generating the next value set your variable to clear or NULL after updating the db, and before updating check whether variable is clear or NULL skip the update process.

That sounds perfect, would you mind putting a bit of sample code together please?

This is my code so far:

<?php
header('refresh:30; url=pachube.php');
require_once( '/pachube_php_library/pachube_functions.php' );
$api_key = "xxxxxxxxxxxxxxxxx";
$pachube = new Pachube($api_key);
$feed = xxxxx;
$data = $pachube->retrieveData ( $feed, "csv" );
$array = explode(',', $data, 5);
$value = $array[0];
echo $value;

	//Connect to database
	$opendb = mysql_connect("localhost", "root", "") or mysql_error("Could not connect to database");
    mysql_select_db("test");

    if ($opendb)
		{
     	mysql_query(" INSERT INTO arduino (data) VALUES ($value)");
		mysql_close($opendb);
		}
		
?>

So i'm guessing i would need to put some sort of "if" statement above the mysql query??

Thanks

<?php
header('refresh:30; url=pachube.php');
require_once( '/pachube_php_library/pachube_functions.php' );
$api_key = "xxxxxxxxxxxxxxxxx";
$pachube = new Pachube($api_key);
$feed = xxxxx;
$data = $pachube->retrieveData ( $feed, "csv" );
$array = explode(',', $data, 5);
$value = $array[0];
echo $value;
if (isset($value) && !empty($value) && $value != NULL)
{
	//Connect to database
	$opendb = mysql_connect("localhost", "root", "") or mysql_error("Could not connect to database");
    mysql_select_db("test");
    if ($opendb)
		{
     	mysql_query(" INSERT INTO arduino (data) VALUES ($value)");
		mysql_close($opendb);
		}
	$value = '';
} else echo "No value is set";
?>

Always welcome! Please mark the thread as solved.