PDA

View Full Version : any php/mysql coders need bit of help



Feck_U
2011-10-08, 22:17
any one here got any experiance with php and mysql i am working on a temp monitor system at work to get me some browny points and need a quick hand


thanks

Sphere
2011-10-08, 22:21
What exactly you want to achieve?

1. Do you use a framework, or try to build it yourself?
2. What do you mean?
3. What's your definition of a "temp monitor system"?
4. There are a lot of existing systems, what do you bring new?
5. Does it involve any (core) API calls?

I work with PHP for a living. It's a shitty language, but it'll do. What exactly you want to achieve?

Feck_U
2011-10-09, 14:01
thanks for helping me out this is what i am tring to achive

7 Temperature sensors —–> Arduino—> Ethernetshield—-> Network—–> (Server(Apache—->PHP—>MySQL)—-> php graph

i got the coding for the arduino sorted this reports the temperature over network to update_db.hp this adds data to the mysql table then i will make a graph from that here is my update_db.hp i cant seem to get it to timestamp in the date field




error_reporting(E_ALL ^ E_NOTICE);

header('Content-type: text/plain');
echo date("d.m.Y-H:i:s") . " Temperatur 1 = " . $_GET['t0'];
echo date("d.m.Y-H:i:s") . " Temperatur 2 = " . $_GET['t1'];
echo date("d.m.Y-H:i:s") . " Temperatur 3 = " . $_GET['t2'];
echo date("d.m.Y-H:i:s") . " Temperatur 4 = " . $_GET['t3'];
echo date("d.m.Y-H:i:s") . " Temperatur 5 = " . $_GET['t4'];
echo date("d.m.Y-H:i:s") . " Temperatur 6 = " . $_GET['t5'];
echo date("d.m.Y-H:i:s") . " Temperatur 7 = " . $_GET['t6'];

$link = mysql_connect("localhost", "8conv", "password") or die("Database Error: " . mysql_error());
mysql_select_db("tempmonitor") or die("Database Error");
$query = "INSERT INTO 8conv(temp1, temp2, temp3, temp4, temp5, temp6, temp7) VALUES ('" . $_GET['t0'] . "', Â*'" . $_GET['t1'] . "', Â*'" . $_GET['t2'] . "', Â*'" . $_GET['t3'] . "','" . $_GET['t4'] . "','" . $_GET['t5'] . "','" . $_GET['t6'] . "')";$result = mysql_query($query) or die("Database Error: " . mysql_error());


mysql_close($link);



here is a pic on what the tables look like

http://i56.tinypic.com/24q7rki.jpg

and i have started on the graph using jpgraph

http://i52.tinypic.com/315zddw.jpg


once i get the timestamp sorted i will look at getting jpgraph to pull the data from the database

Sphere
2011-10-09, 16:10
What exactly do you need help with?

Looks like it's working perfectly if you ask me... Â*:oops:

But why do you use jpgraph?

Personally, I like pChart a lot more, because it renders better, and after some practicing, creates better, smoother graphs if you ask me...

Feck_U
2011-10-09, 16:16
cool i look into that just having trouble when reresh the update_db.php it wont imput itn timestamp it shows it on the page when you refresh but wont go into mysql

also thanks i have a look at pChart

Sphere
2011-10-09, 16:28
If I look at your query...

You're not actually telling MySQL to save the date/time moment...

Change:

"INSERT INTO 8conv(temp1, temp2, temp3, temp4, temp5, temp6, temp7) VALUES ('" . $_GET['t0'] . "', ÂÂ*'" . $_GET['t1'] . "', ÂÂ*'" . $_GET['t2'] . "', ÂÂ*'" . $_GET['t3'] . "','" . $_GET['t4'] . "','" . $_GET['t5'] . "','" . $_GET['t6'] . "')";$result = mysql_query($query) or die("Database Error: " . mysql_error());
to

"INSERT INTO 8conv(date, temp1, temp2, temp3, temp4, temp5, temp6, temp7) VALUES (NOW(), '" . $_GET['t0'] . "', ÂÂ*'" . $_GET['t1'] . "', ÂÂ*'" . $_GET['t2'] . "', ÂÂ*'" . $_GET['t3'] . "','" . $_GET['t4'] . "','" . $_GET['t5'] . "','" . $_GET['t6'] . "')";$result = mysql_query($query) or die("Database Error: " . mysql_error());

NOW() is a generic MySQL statement to save the timestamp (dunno by heart if it's actual date-time format or the Unix timestamp, but the timestamp is easily shown in a readable form via date('format', 'source'); method.

Ow, and please use CamelCaseTypesetting for your database? It's a good habit to have!

Feck_U
2011-10-09, 21:25
thanks so much for help so far how would i go about pulling data from the sql into the chart here is what i got for the chart and the db details file i have sort you a drink or something for your help i think once i get the jist of it i can look into using other charts


db_details.php

// The server host name or number running your MySQL database
// usually 127.0.0.1 or localhost will suffice
$dbhost ÂÂ* ÂÂ*= "localhost";
//
// The username used to log-in to your database server
$dbuser ÂÂ* ÂÂ*="8conv";
//
// The password used to log-in to your database server
$dbpassword ÂÂ* ="******";
//
// The name of the MySQL database we will store the tables in
$database ÂÂ* ="tempmonitor";



here is the graph script




// content="text/plain; charset=utf-8"
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_line.php');
include ('db_details.php');

$datay1 = array(20,15,23,15,46,56,99);
$datay2 = array(12,9,42,8,32,22,67);
$datay3 = array(5,17,32,24,90,32,46);
$datay4 = array(14,22,4,35,12,40,100);
$datay5 = array(45,25,13,35,56,56,10);
$datay6 = array(14,90,62,8,43,10,87);
$datay7 = array(15,47,55,67,80,39,72);

// Setup the graph
$graph = new Graph(900,800);
$graph->SetScale("textlin");

$theme_class=new UniversalTheme;

$graph->SetTheme($theme_class);
$graph->img->SetAntiAliasing(false);
$graph->title->Set('8 Conv');
$graph->SetBox(false);


$graph->img->SetAntiAliasing();

$graph->yaxis->HideZeroLabel();
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);

$graph->xgrid->Show();
$graph->xgrid->SetLineStyle("solid");
$graph->xgrid->SetColor('#E3E3E3');

$graph->yaxis->SetTitle("temperature", "middle");
$graph->xaxis->SetTitle("Days of the week", "middle");
$days = $gDateLocale->GetShortDay();
$graph->xaxis->SetTickLabels($days);

// Create the first line
$p1 = new LinePlot($datay1);
$graph->Add($p1);
$p1->SetColor("#6495ED");
$p1->SetLegend('Probe 1');

// Create the second line
$p2 = new LinePlot($datay2);
$graph->Add($p2);
$p2->SetColor("#B22222");
$p2->SetLegend('Probe 2');

// Create the third line
$p3 = new LinePlot($datay3);
$graph->Add($p3);
$p3->SetColor("#FF1493");
$p3->SetLegend('Probe 3');

// Create the forth line
$p4 = new LinePlot($datay4);
$graph->Add($p4);
$p4->SetColor("#000000");
$p4->SetLegend('Probe 4');

// Create the fith line
$p5 = new LinePlot($datay5);
$graph->Add($p5);
$p5->SetColor("#00FF00");
$p5->SetLegend('Probe 5');

// Create the six line
$p6 = new LinePlot($datay6);
$graph->Add($p6);
$p6->SetColor("#EE9A4D");
$p6->SetLegend('Probe 6');

// Create the seven line
$p7 = new LinePlot($datay7);
$graph->Add($p7);
$p7->SetColor("#461B7E");
$p7->SetLegend('Probe 7');


$graph->legend->SetFrameWeight(1);

// Output line
$graph->Stroke();




THANK YOU

Gisse
2011-10-10, 16:02
If i understand good what you want and what code is for you will need to take data from database and add it to this part


$datay1 = array(20,15,23,15,46,56,99);
$datay2 = array(12,9,42,8,32,22,67);
$datay3 = array(5,17,32,24,90,32,46);
$datay4 = array(14,22,4,35,12,40,100);
$datay5 = array(45,25,13,35,56,56,10);
$datay6 = array(14,90,62,8,43,10,87);
$datay7 = array(15,47,55,67,80,39,72);

You could try to do something like this. Performing SELECT for probe and then creating array from results. If i am not wrong SELECT is returning array in first place. Not sure could you use it directly for $dataX.


$datay1 = array(SELECT Query);

Sphere
2011-10-10, 17:41
mysql_fetch_assoc ;) It's really easy. And try using var_dump($array); , to find out what data is what ;)