www.webdeveloper.com
Results 1 to 7 of 7

Thread: Auto-refresh on MySQL change

Hybrid View

  1. #1
    Join Date
    Aug 2009
    Posts
    53

    Auto-refresh on MySQL change

    I'm making a real-time feedback system & I need to know how to make the viewing page refresh automatically (or show new row) when a new row gets added to a MySQL database.

    Here's what my system does:
    - Somebody writes into a form (index.php)
    - the data goes into a MySQL database
    - I can view what they wrote (display.php)

    I want to know how to make display.php automatically reload when somebody writes in the index.php forms.

  2. #2
    Join Date
    Nov 2008
    Posts
    2,477
    You would have to check at a certain interval for new data. This is probably best done via AJAX to avoid constant page reloads. You could also insert new data into display.php without a reload this way too.

  3. #3
    Join Date
    Aug 2009
    Posts
    53
    I've read that you can do it with AJAX, & I tried it, but it didn't work.

    Here's my display.php file. Hope it's not too confusing, but could you show me where the AJAX parts would go?

    PHP Code:
    <?php
    include('connect.php');
    include(
    'config.php');
    $num mysql_query("SELECT * FROM visitordata");
    $num_rows mysql_num_rows($num);

    if(isset(
    $_COOKIE['logged-in'])){
      echo 
    "<div class=\"top\"><a href=\"logout.php\">Log out</a> | <a href=\"index.php\">View posting page</a> | Number of comments: $num_rows <div class=\"logo\"><img src=\"logo.png\" border=0></div></div>";
      echo 
    "<div class=\"gap\"></div>";
      
    $result mysql_query("select * from visitordata order by id desc limit 10");
      
    //the while loop
      
    $id=$_GET['id'];
      while(
    $r=mysql_fetch_array($result))
      {
        
    //getting each variable from the table
        
    if ($r['id'] % == 0) { echo "<div class=\"even\">"; } else { echo "<div class=\"odd\">"; }
        if(
    $flag==$r['id']){ echo "<div id=\"flagged\">"; } else { echo "<div id=\"post\">"; }
        echo 
    "<div class=\"info\"><a href=\"delete.php?delid=".$r['id']."\"><img src=\"delete.png\" border=\"0\"></a> ";
        if(
    $flag==$r['id']){ echo "<a href=\"?flag=\"><img src=\"flag.png\" border=\"0\"></a>"; } else { echo "<a href=\"?flag=".$r['id']."\"><img src=\"flag.png\" border=\"0\"></a>"; }
        echo 
    " | <div class=\"time\">".$r['time']."</div> | <div class=\"name\">".$r['name']."</div> | <div class=\"location\">".$r['location']."</div></div>";
        echo 
    "<a href=\"mail.php?id=".$r['id']."\"><img src=\"email.png\" border=\"0\"></a> $block | <div class=\"message\">".$r["message"]."</div></div></div>";
      }
    } else {
      echo 
    "You do not have permission to access this page.";
    }
    ?>
    That's the part between the <body> tags I didn't bother with the rest since it was only a link to the CSS file.

  4. #4
    Join Date
    Oct 2009
    Posts
    3
    I think the display.php must return the xml or json, and you must put the last database id in the xml, and your ajax request must send the last id record that they have:


    display.php xml
    Code:
    <data>
    <rowsdata>your data in here</rowsdata>
    <lastid>10</lastid>
    </data>
    And in the html view model you can put this
    Code:
    <div id='showtheresult'> <!-- we will use this div for getting the result -->
      your html code for show 
    </div>
    In javascript when success get the result from display.php you can use
    Code:
    $("#showtheresult").append("the rowsdata value from xml");

  5. #5
    Join Date
    Aug 2009
    Posts
    53
    How would I implement this? I tried, but failed. It displayed everything & it still worked, but when I entered sent in data from the index.php file, it didn't reload. I left it for 5 minutes & nothing. So, how would I implement this? (display.php is written in an above post from me)
    Last edited by mattwidge; 10-19-2009 at 01:20 AM.

  6. #6
    Join Date
    Nov 2008
    Posts
    2,477

  7. #7
    Join Date
    Aug 2009
    Posts
    53
    I have no idea how to implement this. I went through the tutorial, but I don't know how to implement this.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles