- This topic is empty.
-
AuthorPosts
-
March 3, 2014 at 8:22 am #164554
nikwak
ParticipantI would very much like to place the following https://css-tricks.com/using-weather-data-to-change-your-websites-apperance-through-php-and-css/ code on to a new site I am building. I know about changing the CSS and I placing the div class in the space I want the jpgs to go on the page but where do I place the actual php coding?? I know it is going to be so straightforward but, as I say, I am totally new to PHP coding.
I placed the codce at the top of the web page and I had the page set as a hmtl but then changed it to a phtml extension to see if it was something to do with the server but I am probably barking up the wrong tree
Thanking you in advance for any help you can give.March 3, 2014 at 10:57 am #164563__
ParticipantDoes your web host support php? Most servers that support php are configured to recognize the
.php
file extension for php scripts.March 4, 2014 at 3:30 am #164626nikwak
Participantyes web host supports php. That isn’t the problem – the problem is me! I don’t know exactly where to place the php code – is it in the same page as the ‘echo’ or is it in a separate php page or what? If on the same page – is it at the top, in the ‘head’ or ‘body’ sections? I am at a loss really
March 4, 2014 at 6:23 pm #164698__
ParticipantWell, one of the cool things about PHP (object oriented guys would spit out their beer about now) is the fact that you can just put it inside a bunch of HTML.
» spits out beer «
Seriously, though, even if you’re not doing object-oriented code (and you are most likely not), it is beneficial to think of your PHP code in two different categories: logic and templates.
Some PHP code is directly related to displaying things on the output html page: that’s templating stuff. Other code does “work” that is not directly related – makes decisions, gets/organizes data, “behind-the-scenes” work.
Generally speaking, the work should go first (at the top of your script), and the templating stuff (including all of your plain HTML) should go afterwards (at the bottom). It will save you a lot of grief at some point.
The script you’re talking about is, in fact, already organized this way:
$data = get_data("http://weather.yahooapis.com/forecastrss?p=97211&u=f"); $weather_class = format_result(get_match('/<yweather:condition text="(.*)"/isU',$data)); // etc. ...
goes at the top, and then your HTML markup follows at the end (with the
<?php echo $weather_class; ?>
included wherever you want it to appear).March 5, 2014 at 9:08 am #164782nikwak
ParticipantThanks to both of you for your answers – they have really spelt it out to me in a language I can understand and I am very grateful to you
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.