4 Replies - 1109 Views - Last Post: 18 July 2012 - 08:30 AM

#1 mshadow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 03-July 12

refresh contents of div

Posted 17 July 2012 - 04:02 PM

<div id="refresh">
<?php
  if(isset($_POST["from"]))
{
  $mysqli = new mysqli("localhost", "root", "", "library");
  if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;}
 else
 {   
 session_start();
 if(!isset($_SESSION['name'])&&issset($_SESSION['password'])){
 header("location:logi.html");
 }
 else{
 
 $send=$_POST["from"];
 echo "$send";
  
$nm=$_SESSION['name'];
  $result=$mysqli->query("select SEND from request where RECE='$nm';");
  $row=$result->fetch_assoc();
  $sender=$row['SEND'];
  
  $mysqli->real_query("SELECT name, msg FROM message WHERE receiver = '$send' AND name = '$nm' OR receiver = '$nm' AND name = '$send' LIMIT 0 , 30;"); 
    $res=$mysqli->use_result();
    while($row=$res->fetch_assoc())
    {
       echo ">" .$row['name'].":". $row['msg'] . "\n <br>";

    }
  }
 }
}
?>
</div>


hey frnds
this is a div content of my code....i want to refresh it at a regular time interval.... i know about .load() of jquery........but is there any other way to do this.....googled all over but couldn't find anything....ANY IDEAS???

Is This A Good Question/Topic? 0
  • +

Replies To: refresh contents of div

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: refresh contents of div

Posted 17 July 2012 - 05:04 PM

Moved to Javascript
Was This Post Helpful? 0
  • +
  • -

#3 xxxjj18  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 53
  • View blog
  • Posts: 167
  • Joined: 30-November 11

Re: refresh contents of div

Posted 17 July 2012 - 05:09 PM

So you want to update it with the results of the PHP code?

You could use ajax and then use the .html() function to replace the div's content;


$.ajax({
  type: "POST",
  url: "yourFile.php",
  data: { /* any data goes here */ }
}).done(function( msg ) {
  $("#refresh").html(msg);
});



Was This Post Helpful? 0
  • +
  • -

#4 mshadow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 03-July 12

Re: refresh contents of div

Posted 17 July 2012 - 10:38 PM

View Postxxxjj18, on 17 July 2012 - 05:09 PM, said:

So you want to update it with the results of the PHP code?

You could use ajax and then use the .html() function to replace the div's content;


$.ajax({
  type: "POST",
  url: "yourFile.php",
  data: { /* any data goes here */ }
}).done(function( msg ) {
  $("#refresh").html(msg);
});



no no....i dont want any other php file .......i want to refresh the php code inside div tag
Was This Post Helpful? 0
  • +
  • -

#5 xxxjj18  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 53
  • View blog
  • Posts: 167
  • Joined: 30-November 11

Re: refresh contents of div

Posted 18 July 2012 - 08:30 AM

So you want the code in the div to be ran again?

That's what the script I posted does; you save the php code in the div to a php file.

Then you continuously make calls to the file through AJAX and update the div with the results.

This method is good because it helps for you not to mix languages, which is very taboo in web programming.

This will allow for a cleaner, more legible script.

Otherwise, you cannot refresh the php code in the div dynamically without refreshing the page; the PHP is parsed before the browser even renders the HTML, and is not editable after it has already been parsed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1