Hi,

I'm developing a php script that reads data from a mysql db and then puts the data into csv format to then be sent upto Pachube.com for a web app i'm developing. This is a simple problem i'm sure but i cant seem to solve it!

Code below:

<?php

require_once( '../Pachube_PHP_library/pachube_functions.php' );
$api_key = "xxxxxxxxxxxxxxxx";
$pachube = new Pachube($api_key);
echo "<b>Update a manual feed with CSV: </b>";
$url = "http://www.pachube.com/api/xxxx.csv";
$data = $numrows, $numrows1; --------------Problem is here, it doesn't like the format!
$update_status = $pachube->updatePachube ( $url, $data );	
$pachube->debugStatusCode($update_status);
$csv = $pachube->retrieveData ( $url );
echo "<br />";
echo "<br />";
echo $csv;
echo "<br />";
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("test", $con);

$result1 = mysql_query("SELECT timer1 FROM pachubevb order by id desc limit 1");
$numrows=mysql_result($result1,0);
echo $numrows;
echo "<br />";
$result2 = mysql_query("SELECT timer2 FROM pachubevb order by id desc limit 1");
$numrows1=mysql_result($result2,0);
echo $numrows1;

?>

So how do a get two variables "$numrows" and "$numrow1" into a csv format? ie. "value, value"?

Thanks

Thanks for that, i found a way around it in the end, it was that i was trying to update the csv url before selecting from the database! The code below works now!

<?php

require_once( '../Pachube_PHP_library/pachube_functions.php' );
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("test", $con);

$result1 = mysql_query("SELECT timer1 FROM pachubevb order by id desc limit 1");
$numrows=mysql_result($result1,0);
//echo $numrows;
$result2 = mysql_query("SELECT timer2 FROM pachubevb order by id desc limit 1");
$numrows1=mysql_result($result2,0);
//echo $numrows1;

$api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$pachube = new Pachube($api_key);
$url = "http://www.pachube.com/api/xxxx.csv";
$data = $numrows.",".$numrows1;
$update_status = $pachube->updatePachube ( $url, $data );	
$csv = $pachube->retrieveData ( $url );
$array = explode(',', $csv, 5);
$value = $array[0];
echo $value;
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.