posting php code using jquery .html()
<p>simple query,but it's giving me a headache, i need a division to be updated with a changed session variable each time a user clicks on a name,i figured i'd use .html() using jquery to update the division, i don't know if you can do this, but here goes:</p>

<pre><code> &lt;div id="inner"&gt;
 &lt;/div&gt;
</code></pre>

<p>so that's the markup that contains the php which should echo the contents of the specified file, because i'll change the values of the session variables when i click on a name being loaded in another division, i'd need this division inner to reflect these changes, i.e. to change the variables there automatically as well, without refreshing the page, i figured a function of some sort should do this. here are the names:</p>

<pre><code>  &lt;div id="list"&gt;
   &lt;u&gt;&lt;b&gt;FRIENDS:&lt;/b&gt;&lt;/u&gt;
   &lt;br&gt;
    &lt;br&gt;
&lt;?php

mysql_connect("localhost","root","");
mysql_select_db("friendfile");
$jina="BIGBOI";
$querya="SELECT * FROM user_info WHERE user_info.name='$jina'";
$result=mysql_query($querya); 
$row=mysql_fetch_array($result);
$user_id=$row['user_id'];
$query="SELECT name FROM listfriend WHERE listfriend.user_id='$user_id'";
$done=mysql_query($query);
while($rowb=mysql_fetch_array($done))
{
 $rafiki=$rowb['name'];
 echo "&lt;a class='friend'     href='Javascript:makefile(\"".$jina."\",\"".$rafiki."\")'&gt;"."$rafiki"."&lt;/a&gt;"."&lt;br/&gt;";
}
?&gt;
&lt;/div&gt;
</code></pre>

<p>this part is fine, the thing is, i need the div 'inner' to be updated with any change in session variables, here's the function makefile:</p>

<pre><code> function makefile(username,friendname){
var ext=".html";
       //concatenate
       var dash="-";
        var full=username.concat(dash,friendname,dash,ext);
        var str=friendname.concat(dash,username,dash,ext);
$.ajax({
       type:"POST",
       url:"makesend.php",
       data: {full:full},
     //what to do if data was sent:
 success: function(full){
    $("#myresponse").html(full);


       }
        });
      return false;
 }
</code></pre>

<p>so data gets sent to a script the file is made and so on, all working fine, the problem is with the updating of the div "inner" so that it reflects these changes, if i were to declare the variables like this:</p>

<pre><code>   &lt;div id="inner"&gt;
   &lt;?php
    session_start();
       if(file_exists($_SESSION['full'])||file_exists($_SESSION['str'])){
    if(file_exists($_SESSION['full'])&amp;&amp; filesize($_SESSION['full']) &gt; 0)
    {
    $full=$_SESSION['full'];
    $handlle = fopen($full, "r");
    $contents = fread($handlle, filesize($full));
    fclose($handlle);

    echo $contents;
    echo '&lt;script type="text/javascript" src="jquery-1.8.0.min (1).js"&gt;';
    echo '&lt;/script&gt;';
    echo '&lt;script type="text/javascript"&gt;';
    echo 'function loadLog(){       
    var oldscrollHeight = $("#inner").attr("scrollHeight") - 20;
    $.ajax({
        url: \''.$_SESSION['full'].'\',
        cache: false,
        success: function(html){        
            $("#inner").html(html); //Insert chat log into the #chatbox div             
            var newscrollHeight = $("#inner").attr("scrollHeight") - 20;
            if(newscrollHeight &gt; oldscrollHeight){
                $("#inner").animate({ scrollTop: newscrollHeight }, \'normal\'); //Autoscroll to bottom of div
            }               
        },
    });
}
setInterval (loadLog, 2500);';
echo '&lt;/script&gt;';

    }
    else
    {
    $str=$_SESSION['str'];
    if(file_exists($str) &amp;&amp; filesize($_SESSION['str']) &gt; 0)
    {
    $handle = fopen($str, 'r');
    $contents = fread($handle, filesize($str));
    fclose($handle);

    echo $contents;
        $full=$_SESSION['full'];
    $handlle = fopen($full, "r");
    $contents = fread($handlle, filesize($full));
    fclose($handlle);

    echo $contents;
    echo '&lt;script type="text/javascript" src="jquery-1.8.0.min (1).js"&gt;';
    echo '&lt;/script&gt;';
    echo '&lt;script type="text/javascript"&gt;';
    echo 'function loadLog(){       
    var oldscrollHeight = $("#inner").attr("scrollHeight") - 20;
    $.ajax({
        url: \''.$_SESSION['str'].'\',
        cache: false,
        success: function(html){        
            $("#inner").html(html); //Insert chat log into the #chatbox div             
            var newscrollHeight = $("#inner").attr("scrollHeight") - 20;
            if(newscrollHeight &gt; oldscrollHeight){
                $("#inner").animate({ scrollTop: newscrollHeight }, \'normal\'); //Autoscroll to bottom of div
            }               
        },
    });
}
setInterval (loadLog, 2500);';
echo '&lt;/script&gt;';

    }
    }
}

?&gt;

  &lt;/div&gt;
</code></pre>

<p>i'd have to refresh the page to see the changes, but i figured if i did this:</p>

<pre><code> $("#inner").html('&lt;?php
session_start();
if(file_exists($_SESSION['full'])||file_exists($_SESSION['str'])){
    if(file_exists($_SESSION['full']))
    {
    $full=$_SESSION['full'];
    $handlle = fopen($full, "r");
    $contents = fread($handlle, filesize($full));
    fclose($handlle);

    echo $contents;
    echo '&lt;script type="text/javascript" src="jquery-1.8.0.min (1).js"&gt;';
    echo '&lt;/script&gt;';
    echo '&lt;script type="text/javascript"&gt;';
    echo 'function loadLog(){       
    var oldscrollHeight = $("#inner").attr("scrollHeight") - 20;
    $.ajax({
        url: \''.$_SESSION['full'].'\',
        cache: false,
        success: function(html){        
            $("#inner").html(html); //Insert chat log into the #chatbox div             
            var newscrollHeight = $("#inner").attr("scrollHeight") - 20;
            if(newscrollHeight &gt; oldscrollHeight){
                $("#inner").animate({ scrollTop: newscrollHeight }, \'normal\'); //Autoscroll to bottom of div
            }               
        },
    });
}
setInterval (loadLog, 2500);';
echo '&lt;/script&gt;';

    }
    else
    {
    $str=$_SESSION['str'];
    if(file_exists($str))
    {
    $handle = fopen($str, 'r');
    $contents = fread($handle, filesize($str));
    fclose($handle);

    echo $contents;
        $full=$_SESSION['full'];
    $handlle = fopen($full, "r");
    $contents = fread($handlle, filesize($full));
    fclose($handlle);

    echo $contents;
    echo '&lt;script type="text/javascript" src="jquery-1.8.0.min (1).js"&gt;';
    echo '&lt;/script&gt;';
    echo '&lt;script type="text/javascript"&gt;';
    echo 'function loadLog(){       
    var oldscrollHeight = $("#inner").attr("scrollHeight") - 20;
    $.ajax({
        url: \''.$_SESSION['str'].'\',
        cache: false,
        success: function(html){        
            $("#inner").html(html); //Insert chat log into the #chatbox div             
            var newscrollHeight = $("#inner").attr("scrollHeight") - 20;
            if(newscrollHeight &gt; oldscrollHeight){
                $("#inner").animate({ scrollTop: newscrollHeight }, \'normal\'); //Autoscroll to bottom of div
            }               
        },
    });
}
setInterval (loadLog, 2500);';
echo '&lt;/script&gt;';

    }
    }
}

?&gt;');
</code></pre>

<p>and put it at the end of the function that sends the data to the script via ajax, the content in div "inner" would always be up to date. i need help with this, how would i make this work? thanks in advance.</p>
