Welcome to the Cumulus Support forum.

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Cumulus MX V4 beta test release 4.0.0 (build 4017) - 17 March 2024

Legacy Cumulus 1 release v1.9.4 (build 1099) - 28 November 2014 (a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

what am i doing Wong PHP

Other discussion about creating web sites for Cumulus that doesn't have a specific subforum

Moderator: daj

Post Reply
User avatar
dazza1223
Posts: 860
Joined: Sun 25 Jan 2015 8:41 pm
Weather Station: Davis Vantage Pro 2 plus
Operating System: Raspberry pi 4 (4gb)
Location: Worthing
Contact:

what am i doing Wong PHP

Post by dazza1223 »

ive just upgraded to php 7.1 but most off the php script stop working but i read that you need to covert to mysql to mysqli ive done that and it saying that Failed to connect to the database on the server


http://www.davisworthing.co.uk/graphs_monthly.php

plz can someone help me
<?php
include ('../../../utils/db_ro_details.php');

// Standard Source view option check

function check_sourceview () {
global $SITE;
if (isset($_GET['view']) && $_GET['view'] == 'sce') {
$filenameReal = __FILE__;
$download_size = filesize($filenameReal);
header('Pragma: public');
header('Cache-Control: private');
header('Cache-Control: no-cache, must-revalidate');
header('Content-type: text/plain');
header('Accept-Ranges: bytes');
header("Content-Length: $download_size");
header('Connection: close');
readfile($filenameReal);
exit;
}
}

// Just list the PHP source?
check_sourceview();

// get the input parameters
if (isset($_GET["m"])) {
$month = intval($_GET["m"]);
} else {
die("No 'm' parameter supplied");
}

if ($month == "") {
die("Invalid 'm' parameter supplied");
}

// get the input parameters
if (isset($_GET["y"])) {
$year = intval($_GET["y"]);
} else {
die("No 'y' parameter supplied");
}

if ($year == "") {
die("Invalid 'y' parameter supplied");
}

// Connect to the database
$con=@mysqli_connect($dbhost,$dbuser,$dbpassword);
if (!$con) { echo "failed to connect to the database server"; exit(); }

if (!mysqli_select_db($database,$con)) { echo "Failed to connect to the database on the server"; exit(); }

#
# The db querys
#
//$result = $mysqlii->query("SET time_zone='+10:00'");
//if (!$result) { die("ERROR - TZ Statement"); }

$query = "SELECT MAX(MaxTemp), MIN(MinTemp), AVG(AvgTemp), MAX(HighHum), MIN(LowHum), SUM(TotRainFall), MAX(HighWindGust), SUM(TotWindRun), MIN(MinPress), MAX(MaxPress), MAX(HighSolarRad), SUM(HoursSun), MAX(HighAvgWSpeed), ROUND(AVG(DomWindDir),0) FROM Daydata WHERE Year(LogDate) = ".$year." and Month(LogDate) = ".$month."";

$result = mysqli_query($query);
if (!$result) { printf ("ERROR - Bad Select Statement"); exit; }

while($row = mysqli_fetch_row($result)) {
$TMaxM = (float)$row[0];
$TMinM = (float)$row[1];
$TAvgM = number_format((float)$row[2],1);
$HMaxM = (float)$row[3];
$HMinM = (float)$row[4];
$PTotM = (float)$row[5];
$VMaxM = (float)$row[6];
$VTotM = (float)$row[7];
$PMaxM = (float)$row[8];
$PMinM = (float)$row[9];
$SMaxM = (float)$row[10];
$STotM = (float)$row[11];
$WMaxM = (float)$row[12];
$WDirM = (float)$row[13];
}

$query = "SELECT UNIX_TIMESTAMP(LogDate) AS LogDate, MaxTemp, MinTemp, AvgTemp, HighHum, LowHum, TotRainFall, HighWindGust, TotWindRun, MinPress, MaxPress, HighSolarRad, HoursSun, HighAvgWSpeed, DomWindDir FROM Daydata WHERE Year(LogDate) = ".$year." and Month(LogDate) = ".$month." ORDER BY LogDate ASC";
//$query = "SELECT UNIX_TIMESTAMP(LogDate) AS LogDate, MaxTemp, MinTemp, AvgTemp FROM Daydata WHERE LogDate >= DATE_FORMAT(CURDATE() - INTERVAL " . $interval ." MONTH, '%Y-%m-%d') ORDER BY LogDate ASC";

$result = mysqli_query($query);
if (!$result) { printf ("ERROR - Bad Select Statement"); exit; }

// import the rows and put the data into arrays
while($row = mysqli_fetch_row($result)) {
$title[] = $row[0];
$TMax[] = (float)$row[1];
$TMin[] = (float)$row[2];
$TAvg[] = (float)$row[3];
$HMax[] = (float)$row[4];
$HMin[] = (float)$row[5];
$PTot[] = (float)$row[6];
$VMax[] = (float)$row[7];
$VTot[] = (float)$row[8];
$PMax[] = (float)$row[9];
$PMin[] = (float)$row[10];
$SMax[] = (float)$row[11];
$STot[] = (float)$row[12];
$WMax[] = (float)$row[13];
$WDDir[] = (float)$row[14];
}

// put into a single array
// Have to add an offset of 10 minutes to the start-date for some reason?!
//$rows =array(($title[0]+6000) * 1000, 'tmin' => $TMin, 'tmax' => $TMax, 'tavg' => $TAvg, 'hmin' => $HMin, 'hmax' => $HMax, 'rain' => $PTot, 'windr' => $VMax, 'windt' => $VTot, 'pmin' => $PMin, 'pmax' => $PMax,
// 'tminM' => $TMinM, 'tmaxM' =>$TMaxM, 'tavgM' =>$TAvgM, 'hmaxM' =>$HMaxM, 'hminM' =>$HMinM, 'rainM' =>$PTotM, 'windrM' => $VMaxM, 'windtM' => $VTotM, 'pminM' => $PMinM, 'pmaxM' => $PMaxM, 'smax' => $SMax, 'stot' => $STot, 'smaxM' => $SMaxM, 'stotM' => $STotM, 'wmaxM' => $WMaxM, 'wmax' => $WMax, 'wddir' => $WDDir, 'wdirM' => $WDirM);


$rows =array((($title[0]+86400)* 1000), 'tmin' => $TMin, 'tmax' => $TMax, 'tavg' => $TAvg, 'hmin' => $HMin, 'hmax' => $HMax, 'rain' => $PTot, 'windr' => $VMax, 'windt' => $VTot, 'pmin' => $PMin, 'pmax' => $PMax,
'tminM' => $TMinM, 'tmaxM' =>$TMaxM, 'tavgM' =>$TAvgM, 'hmaxM' =>$HMaxM, 'hminM' =>$HMinM, 'rainM' =>$PTotM, 'windrM' => $VMaxM, 'windtM' => $VTotM, 'pminM' => $PMinM, 'pmaxM' => $PMaxM, 'smax' => $SMax, 'stot' => $STot, 'smaxM' => $SMaxM, 'stotM' => $STotM, 'wmaxM' => $WMaxM, 'wmax' => $WMax, 'wddir' => $WDDir, 'wdirM' => $WDirM);

header("Content-type: text/json");
echo json_encode($rows);
?>
Have fun and keep learning

dazza :D

https://www.davisworthing.co.uk

Image
User avatar
rogerthn
Posts: 489
Joined: Thu 11 Apr 2013 6:31 pm
Weather Station: Ecowitt GW1000/GW1003
Operating System: Raspberry Pi OS bullseye aarch64
Location: Trollhättan Sweden
Contact:

Re: what am i doing Wong PHP

Post by rogerthn »

Image
User avatar
dazza1223
Posts: 860
Joined: Sun 25 Jan 2015 8:41 pm
Weather Station: Davis Vantage Pro 2 plus
Operating System: Raspberry pi 4 (4gb)
Location: Worthing
Contact:

Re: what am i doing Wong PHP

Post by dazza1223 »

Lol that what I've been trying with but as I said no luck and thank for getting back to me
Have fun and keep learning

dazza :D

https://www.davisworthing.co.uk

Image
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: what am i doing Wong PHP

Post by beteljuice »

So where have you put mysql2i.class.php and mysql2i.func.php files - and have you set the include path correctly ?
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
dazza1223
Posts: 860
Joined: Sun 25 Jan 2015 8:41 pm
Weather Station: Davis Vantage Pro 2 plus
Operating System: Raspberry pi 4 (4gb)
Location: Worthing
Contact:

Re: what am i doing Wong PHP

Post by dazza1223 »

Hi yh I did that I've check the php logs and there nothink in there so I tryed to convert one bye one but as I said it won't conect to the database I'm sure this can't be that hard as I've seen load off step bye step and none off them worked so then I saw this one thinking it will work but it hasn't
Have fun and keep learning

dazza :D

https://www.davisworthing.co.uk

Image
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: what am i doing Wong PHP

Post by beteljuice »

Looking again - that php file IS mysqli

Code: Select all

// Connect to the database
$con=@mysqli_connect($dbhost,$dbuser,$dbpassword);
if (!$con) { echo "failed to connect to the database server"; exit(); }

if (!mysqli_select_db($database,$con)) { echo "Failed to connect to the database on the server"; exit(); }
So is this path valid and the details correct ?

Code: Select all

include ('../../../utils/db_ro_details.php');
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
dazza1223
Posts: 860
Joined: Sun 25 Jan 2015 8:41 pm
Weather Station: Davis Vantage Pro 2 plus
Operating System: Raspberry pi 4 (4gb)
Location: Worthing
Contact:

Re: what am i doing Wong PHP

Post by dazza1223 »

yh that include ('../../../utils/db_ro_details.php');

is all ok even i put db_ro_details.php in the same dir it still the same
Have fun and keep learning

dazza :D

https://www.davisworthing.co.uk

Image
User avatar
dazza1223
Posts: 860
Joined: Sun 25 Jan 2015 8:41 pm
Weather Station: Davis Vantage Pro 2 plus
Operating System: Raspberry pi 4 (4gb)
Location: Worthing
Contact:

Re: what am i doing Wong PHP

Post by dazza1223 »

ok ive got it to work now but i just got one error but i cant fined the fix to it

http://www.davisworthing.co.uk/graphs_monthly.php

[Sat Feb 02 22:08:36.536404 2019] [:error] [pid 2887] [client 92.27.85.131:59140] PHP Notice: Undefined variable: con in /home/pi/usb/website/utils/graphs_monthly/historicMonthly.php on line 50, referer: http://www.davisworthing.co.uk/graphs_monthly.php


i got the the info from here

https://stackoverflow.com/questions/139 ... -to-mysqli
Have fun and keep learning

dazza :D

https://www.davisworthing.co.uk

Image
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: what am i doing Wong PHP

Post by beteljuice »

That doesn't make sense (see code snippet 3 up)

If $con doesn't exist you haven't even called the database to get a response ?

Edit: you aren't calling with two different files are you ?
Image
......................Imagine, what you will KNOW tomorrow !
Tina
Posts: 2
Joined: Sat 02 Feb 2019 10:25 pm
Weather Station: Davis
Operating System: Win10

Re: what am i doing Wong PHP

Post by Tina »

Seriously. Do not help him.

He has stolen mine and someone else's work again, without permission.

Those charts were originally from laulau and I added my own extra work to show other data forms. The js file is a carbon copy of my file, as usual.

You just cannot stop can you? You need to be banned from here and everybody needs to stop helping him.
User avatar
dazza1223
Posts: 860
Joined: Sun 25 Jan 2015 8:41 pm
Weather Station: Davis Vantage Pro 2 plus
Operating System: Raspberry pi 4 (4gb)
Location: Worthing
Contact:

Re: what am i doing Wong PHP

Post by dazza1223 »

i know mate it a night mare but here is the up to date on off it

Code: Select all

<?php
include ('../../../utils/db_ro_details.php');

but it the line 50 that has the error



// Standard Source view option check

function check_sourceview () {
    global $SITE;
    if (isset($_GET['view']) && $_GET['view'] == 'sce') {
        $filenameReal = __FILE__;
        $download_size = filesize($filenameReal);
        header('Pragma: public');
        header('Cache-Control: private');
        header('Cache-Control: no-cache, must-revalidate');
        header('Content-type: text/plain');
        header('Accept-Ranges: bytes');
        header("Content-Length: $download_size");
        header('Connection: close');
        readfile($filenameReal);
        exit;
    }
}

// Just list the PHP source?
check_sourceview();

// get the input parameters
if (isset($_GET["m"])) {
    $month = intval($_GET["m"]);
} else {
    die("No 'm' parameter supplied");
}

if ($month == "") {
    die("Invalid 'm' parameter supplied");
}

// get the input parameters
if (isset($_GET["y"])) {
    $year = intval($_GET["y"]);
} else {
    die("No 'y' parameter supplied");
}

if ($year == "") {
    die("Invalid 'y' parameter supplied");
}

// Connect to the database
$conn = mysqli_connect($dbhost, $dbuser, $dbpassword, $database);
if ($con) { echo "failed to connect to the database server"; exit(); }


#
# The db querys
#
//$result = $mysqlii->query($conn,"SET time_zone='+10:00'");
//if (!$result) { die("ERROR - TZ Statement"); }

$query = "SELECT MAX(MaxTemp), MIN(MinTemp), AVG(AvgTemp), MAX(HighHum), MIN(LowHum), SUM(TotRainFall), MAX(HighWindGust), SUM(TotWindRun), MIN(MinPress), MAX(MaxPress), MAX(HighSolarRad), SUM(HoursSun), MAX(HighAvgWSpeed), ROUND(AVG(DomWindDir),0) FROM Daydata WHERE Year(LogDate) = ".$year." and Month(LogDate) = ".$month."";

$result = mysqli_query($conn,$query);
if (!$result) { printf ("ERROR - Bad Select Statement"); exit; }

while($row = mysqli_fetch_row($result)) {
	$TMaxM = (float)$row[0];
	$TMinM = (float)$row[1];
	$TAvgM = number_format((float)$row[2],1);
	$HMaxM = (float)$row[3];
	$HMinM = (float)$row[4];
	$PTotM = (float)$row[5];
	$VMaxM = (float)$row[6];
	$VTotM = (float)$row[7];
	$PMaxM = (float)$row[8];
	$PMinM = (float)$row[9];
	$SMaxM = (float)$row[10];
	$STotM = (float)$row[11];
	$WMaxM = (float)$row[12];
	$WDirM = (float)$row[13];		
}

 $query = "SELECT UNIX_TIMESTAMP(LogDate) AS LogDate, MaxTemp, MinTemp, AvgTemp, HighHum, LowHum, TotRainFall, HighWindGust, TotWindRun, MinPress, MaxPress, HighSolarRad, HoursSun, HighAvgWSpeed, DomWindDir FROM Daydata WHERE Year(LogDate) = ".$year." and Month(LogDate) = ".$month." ORDER BY LogDate ASC";
//$query = "SELECT UNIX_TIMESTAMP(LogDate) AS LogDate, MaxTemp, MinTemp, AvgTemp FROM Daydata WHERE LogDate >= DATE_FORMAT(CURDATE() - INTERVAL " . $interval ." MONTH, '%Y-%m-%d') ORDER BY LogDate ASC";

$result = mysqli_query($conn,$query);
if (!$result) { printf ("ERROR - Bad Select Statement"); exit; }

// import the rows and put the data into arrays
while($row = mysqli_fetch_row($result)) {
	$title[] = $row[0];
	$TMax[] = (float)$row[1];
	$TMin[] = (float)$row[2];
	$TAvg[] = (float)$row[3];
	$HMax[] = (float)$row[4];
	$HMin[] = (float)$row[5];
	$PTot[] = (float)$row[6];
	$VMax[] = (float)$row[7];
	$VTot[] = (float)$row[8];
	$PMax[] = (float)$row[9];
	$PMin[] = (float)$row[10];
	$SMax[] = (float)$row[11];
	$STot[] = (float)$row[12];
	$WMax[] = (float)$row[13];
	$WDDir[] = (float)$row[14];
}

// put into a single array
// Have to add an offset of 10 minutes to the start-date for some reason?!
//$rows =array(($title[0]+6000) * 1000, 'tmin' => $TMin, 'tmax' => $TMax, 'tavg' => $TAvg, 'hmin' => $HMin, 'hmax' => $HMax, 'rain' => $PTot, 'windr' => $VMax, 'windt' => $VTot, 'pmin' => $PMin, 'pmax' => $PMax,
//			'tminM' => $TMinM, 'tmaxM' =>$TMaxM, 'tavgM' =>$TAvgM, 'hmaxM' =>$HMaxM, 'hminM' =>$HMinM, 'rainM' =>$PTotM, 'windrM' => $VMaxM, 'windtM' => $VTotM, 'pminM' => $PMinM, 'pmaxM' => $PMaxM, 'smax' => $SMax, 'stot' => $STot, 'smaxM' => $SMaxM, 'stotM' => $STotM, 'wmaxM' => $WMaxM, 'wmax' => $WMax, 'wddir' => $WDDir, 'wdirM' => $WDirM);

			
$rows =array((($title[0]+86400)* 1000), 'tmin' => $TMin, 'tmax' => $TMax, 'tavg' => $TAvg, 'hmin' => $HMin, 'hmax' => $HMax, 'rain' => $PTot, 'windr' => $VMax, 'windt' => $VTot, 'pmin' => $PMin, 'pmax' => $PMax,
			'tminM' => $TMinM, 'tmaxM' =>$TMaxM, 'tavgM' =>$TAvgM, 'hmaxM' =>$HMaxM, 'hminM' =>$HMinM, 'rainM' =>$PTotM, 'windrM' => $VMaxM, 'windtM' => $VTotM, 'pminM' => $PMinM, 'pmaxM' => $PMaxM, 'smax' => $SMax, 'stot' => $STot, 'smaxM' => $SMaxM, 'stotM' => $STotM, 'wmaxM' => $WMaxM, 'wmax' => $WMax, 'wddir' => $WDDir, 'wdirM' => $WDirM);

header("Content-type: text/json");
echo json_encode($rows);
?>
Have fun and keep learning

dazza :D

https://www.davisworthing.co.uk

Image
Tina
Posts: 2
Joined: Sat 02 Feb 2019 10:25 pm
Weather Station: Davis
Operating System: Win10

Re: what am i doing Wong PHP

Post by Tina »

Do not help him!
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: what am i doing Wong PHP

Post by beteljuice »

He has stolen mine and someone else's work again, without permission.
You are quite right of course.

I think the noose will tightened soon .. :roll:
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
dazza1223
Posts: 860
Joined: Sun 25 Jan 2015 8:41 pm
Weather Station: Davis Vantage Pro 2 plus
Operating System: Raspberry pi 4 (4gb)
Location: Worthing
Contact:

Re: what am i doing Wong PHP

Post by dazza1223 »

what you going on about tina

Those charts were originally from laulau yh i know that and if he gave the green light on here to take them that not class as stolen is it

viewtopic.php?t=14275
Have fun and keep learning

dazza :D

https://www.davisworthing.co.uk

Image
Post Reply