Page 1 of 2
PHP Enter the name of the winds according to the tag [wind0dir-act=endir:--]
Posted: Wed Dec 14, 2022 10:34 pm
by Cavaliere
Hello everybody,
I would like to insert in my php page, the name of the winds: Mistral, Tramontana etc..etc..., based on the tag [wind0dir-act=endir:--], I'm inexperienced with php, and I'm trying this code, but It doesn't seem to work, could you help me?
Code: Select all
<?php
switch ($direzione_del_vento)
{
case "WNW":
case "NW":
case "NNW":
$s = "Maestrale";
break;
case "N":
$s = "Tramontana";
break;
case "NNE":
case "NE":
case "ENE":
$s = "Grecale";
break;
case "E":
$s = "Levante";
break;
case "ESE":
case "SE":
case "SSE":
$s = "Scirocco";
break;
case "S":
$s = "Ostro";
break;
case "SSW":
case "SW":
case "WSW":
$s = "Libeccio";
break;
case "W":
$s = "Ponente";
break;
}
print $s
?>
Re: PHP Enter the name of the winds according to the tag [wind0dir-act=endir:--]
Posted: Thu Dec 15, 2022 10:16 am
by wvdkuil
Your code is OK, therefor the value of
$direzione_del_vento is either
empty or
invalid.
When using a switch, you should add a default case if none of the cases is triggered
Change the last lines to
Code: Select all
case "W":
$s = "Ponente";
break;
default:
$s= "Invalid or empty input >$direzione_del_vento<";
}
This will help to locate the problem. Between the >< the invalid data will be displayed. Or nothing if the field $direzione_del_vento is empty.
Also when testing, set error messages on. Change the first line into
Code: Select all
<?php ini_set('display_errors', 'On'); error_reporting(E_ALL);
Wim
Re: PHP Enter the name of the winds according to the tag [wind0dir-act=endir:--]
Posted: Thu Dec 15, 2022 12:24 pm
by Cavaliere
In the meantime, thank you for your reply and for the directions, by entering your codes, the result is this:
But the value $(direzione_del_vento), shouldn't be replaced by the tag : [wind0dir-act=endir:--]
In my opinion, no case is activated and therefore the switch doesn't work, because it doesn't take the data of the wind direction, generated by the tag [wind0dir-act=endir:--] how can I give it this instruction?
Code: Select all
<?php
switch ($direzione_del_vento)
{
case "WNW":
case "NW":
case "NNW":
$s = "Maestrale";
break;
case "N":
$s = "Tramontana";
break;
case "NNE":
case "NE":
case "ENE":
$s = "Grecale";
break;
case "E":
$s = "Levante";
break;
case "ESE":
case "SE":
case "SSE":
$s = "Scirocco";
break;
case "S":
$s = "Ostro";
break;
case "SSW":
case "SW":
case "WSW":
$s = "Libeccio";
break;
case "W":
$s = "Ponente";
break;
default:
$s= "Invalid or empty input >$direzione_del_vento<";
}
print $s
?>
Re: PHP Enter the name of the winds according to the tag [wind0dir-act=endir:--]
Posted: Fri Dec 16, 2022 12:04 pm
by wvdkuil
Cavaliere wrote: Thu Dec 15, 2022 12:24 pm
In the meantime, thank you for your reply and for the directions, by entering your codes, the result is this:
But the value $(direzione_del_vento), shouldn't be replaced by the tag : [wind0dir-act=endir:--]
In my opinion, no case is activated and therefore the switch doesn't work, because it doesn't take the data of the wind direction, generated by the tag [wind0dir-act=endir:--] how can I give it this instruction?
. . .
Question: You added the code to existing PHP-code ?
If so what is the php name of the field which displays ENE just before your output?
That is the name you should use in your script also.
Otherwise post the lines before your <?php and after ?>
It also helps if you post the link to your site.
Re: PHP Enter the name of the winds according to the tag [wind0dir-act=endir:--]
Posted: Fri Dec 16, 2022 3:45 pm
by Cavaliere
wvdkuil wrote: Fri Dec 16, 2022 12:04 pm
Cavaliere wrote: Thu Dec 15, 2022 12:24 pm
In the meantime, thank you for your reply and for the directions, by entering your codes, the result is this:
But the value $(direzione_del_vento), shouldn't be replaced by the tag : [wind0dir-act=endir:--]
In my opinion, no case is activated and therefore the switch doesn't work, because it doesn't take the data of the wind direction, generated by the tag [wind0dir-act=endir:--] how can I give it this instruction?
. . .
Question: You added the code to existing PHP-code ?
If so what is the php name of the field which displays ENE just before your output?
That is the name you should use in your script also.
Otherwise post the lines before your <?php and after ?>
It also helps if you post the link to your site.
Hi, of course I added the php code, on the sheet where the meteobridge tags are, I add the complete code and also the link to the page, I have problems making the temperature trend arrows appear.
Ecco il link alla pagina:
http://www.ombarcellonapg.com/saratoga/dashboard2.php
Code: Select all
table align="center" class="tabella" style="width:1000" >
<tbody>
<tr>
<th height="30" colspan="3" class="intestazione"><p>TEMPERATURA</p></th>
<th width="314" height="30" class="intestazione"><p>VENTO</p></th>
<th width="250" height="30" class="intestazione"><p>PIOGGIA</p></th>
</tr>
<tr>
<td height="120" colspan="3"><center><div style="width:100px; height:30px; padding:5x; align-content: center; color: #FFFFFF;">[th0temp-act.1:--]° C</div></center>
<div style="width:100px; height:30px; padding:5x; font-size:15px; margin:auto; padding-left: 20px; color: #FFFFFF;">[th0temp-delta10:--]°C </div></td>
<?php
if(( $valore[th0temp-delta10] > 0.0 ) ){ $src = "trendUp.png"; }
if(( $valore[th0temp-delta10] = 0.0 ) ){ $src = "trendNeutral.png"; }
if(( $valore[th0temp-delta10] < 0.0 ) ){ $src = "trendDown.png"; }
?>
<img src="<?php echo $src; ?>" alt="" />
<td height="120"><center><div style="width:100px; height:30px; float: left; margin-left: 15px; padding:5px; color: #FFFFFF;">[wind0wind-act] km/h </div>
<div style="width:100px; height:30px; float: right; margin-right: 15px; padding:5px; color: #FFFFFF;">Raffica:[wind0wind-dmax=kmh.1:] km/h</div>
<div style="width:100px; height:30px padding:5x; color: #FFFFFF;"> [wind0dir-act.0]° </div>
<div style="width:100px; height:30px; padding:5x; color: #FFFFFF;"> [wind0dir-act=endir:--]</div>
<div style="width:100px; height:30px; padding:5x; color: #FFFFFF;"> [wind*wind-act=bft.0:--] </div></center>
<?php
switch ($direzione_del_vento)
{
case "WNW":
case "NW":
case "NNW":
$s = "Maestrale";
break;
case "N":
$s = "Tramontana";
break;
case "NNE":
case "NE":
case "ENE":
$s = "Grecale";
break;
case "E":
$s = "Levante";
break;
case "ESE":
case "SE":
case "SSE":
$s = "Scirocco";
break;
case "S":
$s = "Ostro";
break;
case "SSW":
case "SW":
case "WSW":
$s = "Libeccio";
break;
case "W":
$s = "Ponente";
break;
default:
$s= "Invalid or empty input >$direzione_del_vento<";
}
print $s
?> </p></td>
Re: PHP Enter the name of the winds according to the tag [wind0dir-act=endir:--]
Posted: Sat Dec 17, 2022 12:49 pm
by wvdkuil
I did not understand exactly what you were doing.
Add one line just before the switch
It should look like
Code: Select all
$direzione_del_vento = "[wind0dir-act=endir:--]";
switch ($direzione_del_vento)
That should work.
Re: PHP Enter the name of the winds according to the tag [wind0dir-act=endir:--]
Posted: Sat Dec 17, 2022 6:34 pm
by Cavaliere
wvdkuil wrote: Sat Dec 17, 2022 12:49 pm
I did not understand exactly what you were doing.
Add one line just before the switch
It should look like
Code: Select all
$direzione_del_vento = "[wind0dir-act=endir:--]";
switch ($direzione_del_vento)
That should work.
So, now by inserting the code from indicated, on the page on which I put links, to the previous post. The wind direction is written, but what I wanted to do was to make the name of the type of wind appear, as you can see in the php code the various names of the wind, mistral, tramontana, sirocco .... the switch code should according to to the wind direction, write the name of the wind itself.
I hope I explained myself better.
Re: PHP Enter the name of the winds according to the tag [wind0dir-act=endir:--]
Posted: Sat Dec 17, 2022 7:27 pm
by wvdkuil
It seems the text is displayed but it is in black.
So it is not visible on the black background.
Re: PHP Enter the name of the winds according to the tag [wind0dir-act=endir:--]
Posted: Sun Dec 18, 2022 10:22 am
by Cavaliere
wvdkuil wrote: Sat Dec 17, 2022 7:27 pm
It seems the text is displayed but it is in black.
So it is not visible on the black background.
Yes yes I know it's hard to see each other on a black background, I have to change the color.
But what I want to get written, is not SW, W, WNW, S, SW, E....etc....
I would like him to write the name of the wind: Maestrale, Ponente, Tramontana, Scirocco, Libeccio.
If you look at the php switch code, case based:
Code: Select all
switch ($direzione_del_vento)
{
case "WNW":
case "NW":
case "NNW":
$s = "Maestrale"; Must write and appear this
break;
case "N":
$s = "Tramontana"; Must write and appear this
break;
Re: PHP Enter the name of the winds according to the tag [wind0dir-act=endir:--]
Posted: Sun Dec 18, 2022 11:46 am
by wvdkuil
I copied your html from a browser, inserted the PHP code from your post and it ran correctly.
=> attached screenshot
Please make a zip of the template file your Meteobridge is reading and processing.
Attach that file to your next post
I can test that with my MB-nano and find the type or whatever is happening.
Wim
Re: PHP Enter the name of the winds according to the tag [wind0dir-act=endir:--]
Posted: Sun Dec 18, 2022 11:55 am
by Cavaliere
wvdkuil wrote: Sun Dec 18, 2022 11:46 am
I copied your html from a browser, inserted the PHP code from your post and it ran correctly.
=> attached screenshot
Please make a zip of the template file your Meteobridge is reading and processing.
Attach that file to your next post
I can test that with my MB-nano and find the type or whatever is happening.
Wim
I use the basic meteobridge: Model TL-MR3020V3
Maybe that's the problem?
Re: PHP Enter the name of the winds according to the tag [wind0dir-act=endir:--]
Posted: Sun Dec 18, 2022 12:14 pm
by wvdkuil
Cavaliere wrote: Sun Dec 18, 2022 11:55 am
wvdkuil wrote: Sun Dec 18, 2022 11:46 am
I copied your html from a browser, inserted the PHP code from your post and it ran correctly.
=> attached screenshot
Please make a zip of the template file your Meteobridge is reading and processing.
Attach that file to your next post
I can test that with my MB-nano and find the type or whatever is happening.
Wim
I use the basic meteobridge: Model TL-MR3020V3
Maybe that's the problem?
No, for inserting MB-values all MB devices are the same.
The template file MB uses to generate and upload as . . /saratoga/dashboard2.php
That is the file I need to test.
Wim
Re: PHP Enter the name of the winds according to the tag [wind0dir-act=endir:--]
Posted: Sun Dec 18, 2022 12:29 pm
by Cavaliere
wvdkuil wrote: Sun Dec 18, 2022 12:14 pm
Cavaliere wrote: Sun Dec 18, 2022 11:55 am
wvdkuil wrote: Sun Dec 18, 2022 11:46 am
I copied your html from a browser, inserted the PHP code from your post and it ran correctly.
=> attached screenshot
Please make a zip of the template file your Meteobridge is reading and processing.
Attach that file to your next post
I can test that with my MB-nano and find the type or whatever is happening.
Wim
I use the basic meteobridge: Model TL-MR3020V3
Maybe that's the problem?
No, for inserting MB-values all MB devices are the same.
The template file MB uses to generate and upload as . . /saratoga/dashboard2.php
That is the file I need to test.
Wim
Here is the template that uses the dashboard2.php page to be generated:
http://www.ombarcellonapg.com/saratoga/dashboard1.php
Re: PHP Enter the name of the winds according to the tag [wind0dir-act=endir:--]
Posted: Sun Dec 18, 2022 12:59 pm
by wvdkuil
A template file can not be a .php file when addressed with an url
Test yourself
1. Click on the link in your post
2. Check if the php instructions are still there. They are gone.
You should
1. rename . . ./saratoga/dashboard1.php
to . . ./saratoga/dashboard1.txt
2. Change the .php in the filename after "Modello" also to .txt
3. Click on "Reload template" or "Ricarica modello"
Remember: Every .php file leaving the web-erver via an URL (as in the browser) will be executed before it is sent to the requestor.
Succes, Wim
Re: PHP Enter the name of the winds according to the tag [wind0dir-act=endir:--]
Posted: Sun Dec 18, 2022 1:39 pm
by Cavaliere
wvdkuil wrote: Sun Dec 18, 2022 12:59 pm
A template file
can not be a .php file when addressed with an url
Test yourself
1. Click on the link in your post
2. Check if the php instructions are still there. They are gone.
You should
1.
rename . . ./saratoga/dashboard1.
php
to . . ./saratoga/dashboard1.
txt
2.
Change the .php in the filename after "Modello" also to .txt
3. Click on "Reload template" or "Ricarica modello"
Remember: Every .php file leaving the web-erver via an URL (as in the browser) will be executed
before it is sent to the requestor.
Succes, Wim
I just tried your changes by renaming the Dashboard1.php file to Dashboard1.txt
http://www.ombarcellonapg.com/saratoga/dashboard1.txt
only now on the page
http://www.ombarcellonapg.com/saratoga/dashboard2.php , the dashboard.php file remains empty after I reload the template, is this normal? Do I need to make any changes?
can't see anything anymore why? Have I reloaded the model?
I also enclose the changes to the meteobridge below.