PHP & Java poll script displays same data multiple times after host has upgraded php to 5.4
<p>I have been asked to fix a script on a webpage that has stopped working correctly since the webhost upgraded their supported version of php to 5.4, I have already tried downgrading the version via a htaccess file but without success.</p>

<p>The script basically uses a very simple database to store questions and log votes against them, it uses Java to actually display the questions and their answers and I think its this bit is causing the issues.</p>

<p>There are 5 questions in the database and the actual page itself shows the last question 5 times, which leads me to suspect that a variable is not being cleared somewhere. </p>

<p>Here are the scripts</p>

<pre><code>$topPart = "";
$botPart = "";
$query = mysql_query("SELECT * FROM questions");
while ($row = mysql_fetch_assoc($query)) {
    //display question
    $topPart .= "pollNum=" . $row['id'] . ";\n";
    $topPart .= "$('#loader'+pollNum).fadeIn();\n";
    $topPart .= "$.get('poll.php', 'pollid='+pollNum, function(data, status){\n";
    $topPart .= "loadpoll(data, status, '". $row['id'] ."')\n";
    $topPart .= "});\n";

    $botPart .= "&lt;div id=\"pollcontainer" . $row['id'] . "\" class=\"question\" &gt;". $topPart . "&lt;/div&gt;\n";
    $botPart .= "&lt;p id='loader" . $row['id'] . "'&gt;Loading...&lt;/p&gt;";
</code></pre>

<p>I believe this bit is working ok since when examining the page the id's and classes are all numbered correctly, its the actual questions that repeat, the surrounding divs number correctly. This is the java... I know nothing about Java...</p>

<pre><code>&lt;script&gt;
$(function(){
var pollNum;
&lt;?php
echo $topPart;
?&gt;

function loadpoll(data, status, pollNum){
    //alert(pollNum);
    var pollcontainer=$('#pollcontainer'+pollNum);
    var loader=$('#loader'+pollNum);
    pollcontainer.html(data);
    animateResults(pollcontainer);
    pollcontainer.find('#viewresult'+pollNum).click(function(){
        //if user wants to see result
        $('#formcontainer'+pollNum).fadeOut(100, function(){
            loader.fadeIn();
            $.get('poll.php', 'pollid='+pollNum+'&amp;result=1', function(data,status){
            loadpoll(data,status, pollNum);
            });
        });
        //prevent default behavior
        return false;
    }).end()
    pollcontainer.find('#viewvote'+pollNum).click(function(){
        //if user wants to see result
        $('#formcontainer'+pollNum).fadeOut(100, function(){
            loader.fadeIn();
            $.get('poll.php', 'pollid='+pollNum, function(data,status){
                loadpoll(data,status, pollNum);
            });
        });
        //prevent default behavior
        return false;
    }).end()
    .find('#pollform'+pollNum).submit(function(){
        var selected_val=$(this).find('input[name=poll]:checked').val();
        if(selected_val!=''){
            //post data only if a value is selected
            loader.fadeIn();
            $.post('poll.php', $(this).serialize(), function(data, status)       {
                $('#formcontainer'+pollNum).fadeOut(100, function(){
                    $(this).html(data);
                    animateResults(this);
                    loader.fadeOut();
                });
            });
        }
        //prevent form default behavior
        return false;
    });
    loader.fadeOut();

}

function showresults(data, status, pollNum){
    var pollcontainer=$('#pollcontainer'+pollNum);
    var loader=$('#loader'+pollNum);
            pollcontainer.fadeOut(1000, function(){
                $(this).html(data);
                animateResults(this);

                pollcontainer.find('#viewvote'+pollNum).click(function(){
                    //if user wants to see result
                    loader.fadeIn();
                    $.get('poll.php', 'pollid'+pollNum, function(data,status){
                        pollcontainer.fadeOut(1000, function(){
                            $(this).html(data);
                            animateResults(pollcontainer);
                        });
                        loader.fadeOut();
                    });
                    //prevent default behavior
                    return false;
                }).end()


            });
            loader.fadeOut();

}

function animateResults(data){
    $(data).find('.bar').hide().end().fadeIn('slow', function(){
                        $(this).find('.bar').each(function(){
                            var bar_width=$(this).css('width');
                            $(this).css('width', '0').animate({ width: bar_width }, 1000);
                        });
                    });
}

});
</code></pre>
