1

I am trying to make a php file in which I will send data from database and through them i will show 0 or 1. In my example I have a table with two user_ids and a parameter in which takes the value 0 or 1. From test.php I fill a form by giving the user_id and I submit it. When I submit it for this user the parameter in becomes 0 if it was 1 and vise versa. In next.php I use <iframe src="show.php"> and in show.php I show the user_id and in. What I want is when I submit a user_id, immediately to see the changes in show.php. What I did is to refresh the page all the time but it was too disturbing. Can you suggest something else? Here is some code.

test.php

<?php
require_once 'include_php/db.php';
global $dbcnx;
?>
<form action="" method="get">
    <input type="text" name="id"/>
    <input type="submit" name="submit"/>
</form>

<?php

if(isset($_GET['submit']))
{
    $id = $_GET['id'];
    $res = mysqli_query($dbcnx, "select * from people where uid = ".$id.";");
    $row = mysqli_fetch_array($res);

    if($row['in'] == 0) $up = mysqli_query($dbcnx, "UPDATE `people` SET `in`=1 WHERE uid=".$id.";");
    else $up = mysqli_query($dbcnx, "UPDATE `people` SET `in`=0 WHERE uid=".$id.";");
}

show.php

<?php
require_once 'include_php/db.php';
global $dbcnx;

$res = mysqli_query($dbcnx, "select * from people");

while($row = mysqli_fetch_array($res))
{
    echo $row['uid']." ".$row['in']."<br/>";
}

print "<script>window.location.replace('show.php');</script>"; //here is the disturbing refresh

next.php

<iframe src="show.php">

1 Answers1

2

What you want is live updates without hard refreshing your page. You can achieve this by using AJAX requests, or by using websockets.

With an ajax request, you could easily set a timeout function to refresh your iframe every x-seconds/minutes.

This question gives a good description on how to give it a go.

Community
  • 1
  • 1
Jeroen Bellemans
  • 2,049
  • 2
  • 25
  • 42
  • Thanks for the response. I will upvote and accept your answer in a few days, because i stopped working for today and WEEKEND IS COMING!! – dimitris diamond Jul 24 '15 at 13:53