Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8499865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:47:00+00:00 2026-06-11T00:47:00+00:00

I wrote (thanks to Stackoverflow help, too) a PHP script (called wunder_temp.php) which shows

  • 0

I wrote (thanks to Stackoverflow help, too) a PHP script (called wunder_temp.php) which shows the temperature and location for a given number of Weatherunderground.com Stations.

I included this script in my footer, and it works well BUT on a single page.
If I open http://www.flapane.com/guestbook/guestbook.php the temperatures won’t be shown in my footer, and error.log says:
[09-Sep-2012 09:46:45 UTC] PHP Fatal error: [] operator not supported for strings in /home/xxx/public_html/wunder_temp.php on line 47

$display = file($cachename, FILE_IGNORE_NEW_LINES); //ignore \n for non-reporting stations
foreach ($display as $key=>$value){
    if($key % 2 == 0){  
         $temperature[] = $value; // EVEN (righe del file cache pari)
    }else{
         $location[] = $value;  // ODD - **HERE IS LINE 47**
    }
}

The weird thing is that guestbook.php is the ONLY page of my website where wunder_temp.php doesn’t work.

What the above code does is reading the cachefile and put in a $temperature[] array the even lines and in $location[] array the odd lines.
Here’s a sample from my cachefile:

26.8
Stadio San Paolo di Napoli, Napoli
24.4
Pozzuoli

Honestly I don’t know why I see that errors just on my guestbook page.

It turns out that the “culprit” is the function loadmore.php which loads the guestbook comments (and which is included in guestbook.php) using a twitter-style ajax function. If I don’t include it, wunder_temp.php works well, and it doesn’t produce any error.

loadmore.php:

<div id='contcomment'>
<div class="timeline" id="updates">
<?php
$sql=mysql_query("select * from gbook_comments ORDER BY id DESC LIMIT 9");
while($row=mysql_fetch_array($sql))
{
$msg_id=$row['id'];
$name=$row['name'];
$url=$row['url'];
$email=$row['email'];
$location=$row['location'];
$date= strtotime($row['dt']); //unix timestamp
$country_code=$row['country_code'];
$message=$row['body'];


        $link_open = '';
        $link_close = '';

        if($url){

            // If the person has entered a URL when adding a comment,
            // define opening and closing hyperlink tags

            $link_open = '<a href="'.$url.'" target="_blank" rel="nofollow">';
            $link_close =  '</a>';
        }

// Needed for the default gravatar image:
        $url_grav = 'http://'.dirname($_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]).'/img/default_avatar.gif';



        // Show flags
        $image = strtolower($country_code) . ".png";
        if (file_exists("./img/flags/" . $image)){
        $show_image = true;
        $image_link = "<img src='/guestbook/img/flags/$image' alt='user flag' />";
        }else{
        $show_image = false;
        }


        echo    '<div class="comment">
                <div class="avatar">
                    '.$link_open.'
                    <img src="http://www.gravatar.com/avatar/'.md5($email).'?size=50&amp;default='.urlencode($url_grav).'" alt="gravatar icon" />
                    '.$link_close.'
                </div>

                <div class="name">'.$link_open.$name.$link_close.' </div><div class="location"><i>(da/from '.$location.' '.$image_link.' )</i></div>
                <div class="date" title="Added at '.date('H:i \o\n d M Y',$date).'">'.date('d M Y',$date).'</div>
                <p>'.$message.'</p>

            </div>' ;
} ?>
</div>
<div id="more<?php echo $msg_id; ?>" class="morebox">
<a href="#" class="more" id="<?php echo $msg_id; ?>">Carica Commenti pi&ugrave; vecchi / Load older entries</a>
</div>
</div>

ajax_more.js AJAX twitter-style load-more-comments function:

$(function() {
//More Button
$('.more').live("click",function() 
{
var ID = $(this).attr("id");
if(ID)
{
$("#more"+ID).html('<img src="moreajax.gif" />');

$.ajax({
type: "POST",
url: "ajax_more.php",
data: "lastmsg="+ ID, 
cache: false,
success: function(html){
$("div#updates").append(html);
$("#more"+ID).remove();
}
});
}
else
{
$(".morebox").html('Nessun altro commento / No more comments');

}


return false;


});
});

ajax_more.php (needed by the above script):

<? 

include "connect.php"; 

if(isSet($_POST['lastmsg']))
{
$lastmsg=$_POST['lastmsg'];
$lastmsg=mysql_real_escape_string($lastmsg);
$result=mysql_query("select * from gbook_comments where id<'$lastmsg' order by id desc limit 9");
$count=mysql_num_rows($result);
while($row=mysql_fetch_array($result))
{
$msg_id=$row['id'];
$name=$row['name'];
$url=$row['url'];
$email=$row['email'];
$location=$row['location'];
$date= strtotime($row['dt']); //unix timestamp
$country_code=$row['country_code'];
$message=$row['body'];


        $link_open = '';
        $link_close = '';

        if($url){

            // If the person has entered a URL when adding a comment,
            // define opening and closing hyperlink tags

            $link_open = '<a href="'.$url.'" target="_blank" rel="nofollow">';
            $link_close =  '</a>';
        }

// Needed for the default gravatar image:
        $url_grav = 'http://'.dirname($_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]).'/img/default_avatar.gif';



        // Show flags
        $image = strtolower($country_code) . ".png";
        if (file_exists("./img/flags/" . $image)){
        $show_image = true;
        $image_link = "<img src='/guestbook/img/flags/$image' alt='user flag' />";
        }else{
        $show_image = false;
        }


    echo    '<div class="comment">
                <div class="avatar">
                    '.$link_open.'
                    <img src="http://www.gravatar.com/avatar/'.md5($email).'?size=50&amp;default='.urlencode($url_grav).'" alt="gravatar icon" />
                    '.$link_close.'
                </div>

                <div class="name">'.$link_open.$name.$link_close.' </div><div class="location"><i>(da/from '.$location.' '.$image_link.' )</i></div>
                <div class="date" title="Added at '.date('H:i \o\n d M Y',$date).'">'.date('d M Y',$date).'</div>
                <p>'.$message.'</p>

            </div>' ;       

}


?>

<div id="more<?php echo $msg_id; ?>" class="morebox">
<a href="#" id="<?php echo $msg_id; ?>" class="more">Carica Commenti pi&ugrave; vecchi / Load older entries</a>
</div>

<?php
}
?>

Any help is appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:47:02+00:00Added an answer on June 11, 2026 at 12:47 am

    $location is already a string on that page. This is why you properly initialize variables before you use them:

    $temperature = $location = array();
    
    foreach ($display as $key => $value){
        if ($key % 2 == 0){  
             $temperature[] = $value;
        } else {
             $location[] = $value;
        }
    }
    

    Even better, separate your variable scopes better so you don’t get a name clash like that. Use functions and classes with their private variable scopes and don’t put everything in the global scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

thanks to help from stackoverflow posters I have set up some oop javascript. However,
THANKS FOR HELPING!!! Ok... So I am trying to write a script that will
I wrote some script in a site. The script makes a new spreadsheet and
I have wrote a very simple php upload. But I want to insert image
With the help of some very gracious stackoverflow contributors in this post , I
I have a script on my site ('write-review.php') that takes an optional url parameter
This is the third time I've tried getting help with this on stackoverflow. Basically
Recently with help of stackoverflow i came to know how to match text files
Whenever I type in a phone number, this program below that I wrote to
Almost 6 months ago, I asked a question on stackoverflow Software to help in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.