tags:

views:

40

answers:

2
 <?php
    $xml = simplexml_load_file('http://www.google.com/ig/api?weather=London');
    $information = $xml->xpath("/xml_api_reply/weather/forecast_information");
    $current = $xml->xpath("/xml_api_reply/weather/current_conditions");
    $forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
    ?>
    <html>
    <head>
        <title>Google Weather API</title>
    </head>
    <body>
        <h1><?php print $information[0]->city['data']; ?></h1>
        <h2>Today's weather</h2>
        <div class="weather">       
            <img src="<?php echo  'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"?>
            <span class="condition">
            <?php echo round(conver_f_c($current[0]->temp_f['data'])); ?>&deg; C,
            <?php echo $current[0]->condition['data'] ?>
            </span>
        </div>
        <h2>Forecast</h2>
        <?php foreach ($forecast_list as $forecast) : ?>
        <div class="weather">
            <img src="<?php echo 'http://www.google.com' . $forecast->icon['data']?>" alt="weather"?>
            <div><?php echo $forecast->day_of_week['data']; ?></div>
            <span class="condition">
                <?php echo round(conver_f_c($forecast->low['data'])); ?>&deg; C - <?php echo round(conver_f_c($forecast->high['data'])); ?>&deg; C,
                <?php echo $forecast->condition['data'] ?>
            </span>
        </div>  
        <?php endforeach ?>
    </body>
</html>

<?php
function conver_f_c($F){

    return  $C = ($F − 32) * 5/9;
}

I want Out somthing like this manner of the horizontal ,

Even i tried UL LI WITH display inline but it goes failed,

Tell me some good suggestion for my probme,

I want exactly like horizontal, expecting exactly like screen shot ,

Tell me How to render using php Thanks

alt text

Above snippet present display out verticly , i want o change that verticle to horizonatal , somthing like this screen shot

+1  A: 
<table>...</table>

Update

From your latest comment so far:

i know how to fetch array and display it, but i dont know to fetch and display in the verticl manner that is the stuck up

I feel this is going to be a stupid answer but it appears to be what you don't understand...

The web is based in a markup language called HTML. This language has tags (delimited by angle-brackets) that allow you to define the structure of a document. On top of this, you have another language called CSS. This other lang allow you to define how HTML is going to be displayed on screen.

You may argue that you already have a web page and you've written it with the PHP language instead of the two other langs I've mentioned. That's not enterely true: you code in PHP, sure, but you use PHP to generate HTML. And it's HTML what finally reaches the browser (Firefox, Explorer...). PHP is executed in the web server, not in the browser. The browser can only see whatever HTML you've generated.

To sum up: you have to forget about PHP, Google and the whole weather thingy. You first need to write a static HTML document and style it with CSS. Once you've done with it, you can finally replace the parts of the information that are dynamic with values taken from your PHP variables.

And since you seem to need a table to display tabular data, the appropriate HTML tag is <table>:

<table>
    <tr>
        <th>Web</th>
        <th>Thu</th>
        <th>Fri</th>
        <th>Sat</th>
    </tr>
    <tr>
        <td><img src="/path/to/pics/cloudy.png" width="25" height="25" alt="Cloudy"></td>
        <td><img src="/path/to/pics/sunny.png" width="25" height="25" alt="Sunny"></td>
        <td><img src="/path/to/pics/rainy.png" width="25" height="25" alt="Rainy"></td>
        <td><img src="/path/to/pics/cloudy.png" width="25" height="25" alt="Cloudy"></td>
    </tr>
    <tr>
        <td>26ºC</td>
        <td>26ºC</td>
        <td>22ºC</td>
        <td>25ºC</td>
    </tr>
<table>

I suggest you find some tutorials about basic HTML and CSS. They'll be of invaluable help.

Álvaro G. Vicario
:o [comment padding]
Andy E
A: 

This is what's done by Google :

http://jsfiddle.net/bW8NA/1

Kaaviar
First please understnad . what am asking , if my question is not an understandable manner , plz excuse me ,i know html,css layout design , the thing is in the weather please look , To display three days weather , i used foreach , My problem is ,How to use the table tr td inside the foreach , becoz if i create table in side foreach , every time table will create , and also that wont make in horozonatl view, it simple dislay verticle view only,,,
Bharanikumar
padding: 5px 5px 0pt; float: left; problem fixed
Bharanikumar