Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6822271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:38:35+00:00 2026-05-26T21:38:35+00:00

I have a news feed that has been developed using PHP, MySQL, and jQuery.

  • 0

I have a news feed that has been developed using PHP, MySQL, and jQuery. The news feed does it’s job by getting new content every 5 seconds. However, this is done by a “refresh” of the complete content. I want to only ADD any new content to the news feed. I want a fade in or scroll effect to be used (jQuery) for this to occur. The items already loaded should stay on the feed and NOT reload with any new content. How can I do this?

Here are my 2 pages and code.

feed.php

 <body >

    <script>
    window.setInterval(function(){
      refreshNews();
    }, 5000);
    </script>




    <div id="news"></div>


    <script>

        function refreshNews()
        {
            $("#news").fadeOut().load("ajax.php", function( response, status, xhr){

                if (status == "error"){

                }
                else
                {
                    $(this).fadeIn();
                }
            });
        }
    </script>
    </body>
    </html>

ajax.php

<?php require_once('../../Connections/f12_database_connect.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_f12_database_connect, $f12_database_connect);
$query_newsfeed_q = "SELECT * FROM newsfeed ORDER BY pk DESC";
$newsfeed_q = mysql_query($query_newsfeed_q, $f12_database_connect) or die(mysql_error());
$row_newsfeed_q = mysql_fetch_assoc($newsfeed_q);
$totalRows_newsfeed_q = mysql_num_rows($newsfeed_q);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>

<body>
<table border="1">
  <tr>
    <td>pk</td>
    <td>title</td>
    <td>content</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_newsfeed_q['pk']; ?></td>
      <td><?php echo $row_newsfeed_q['title']; ?></td>
      <td><?php echo $row_newsfeed_q['content']; ?></td>
    </tr>
    <?php } while ($row_newsfeed_q = mysql_fetch_assoc($newsfeed_q)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($newsfeed_q);
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:38:36+00:00Added an answer on May 26, 2026 at 9:38 pm

    I am not quite sure exactly how you have this setup, but it does not seem right:

    1. Create a file that only contains the php code, and this file is going to return a json object that will contain the up to date news; you will parse the object on the client side. The following is an example of what the response of this php file will look like.

    newsFeed.php

    <php
         $array_with_news = array('news1' => array('pk' => 'pk1', 'title' => 'title1', 'content' => 'title2'), 'news2' => array('pk' => 'pk2', 'title' => 'title2', 'content' => 'content2'));
    
         echo json_encode($array_with_news);
    ?>
    
    1. The second file is going to contain both feed.php and the rest of ajax.php. When you do your ajax called for the updated news, the newly created php file will response with a json object that you will parse and set the values of the table with its up to date content.

    index.php

    <html>
    <head>
    <script type="text\javascript">
    
    window.setInterval(function(){
      updateNews();
    }, 5000);
    
    
    function updateNews(){
     var scope = this;
     $.getJSON('newsFeed.php*', function(data) {
      //data will contain the news information
      $.each(data, function(index, value) {
       this.addNewsRow(value);
      });
    
     });
    }
    
    function addNewsRow(newsData){
     //this function will add html content 
     var pk = newsData.pk, title = newsData.title, content = newsData.content;
     $('#news').append(pk + ' ' + title + ' ' + content);
    }
    </script>
    </head>
    <body>
     <div id="news"></div>
    </body>
    </html>
    

    I have not test this, but this is the overall idea of how it should work. index.php is where the user is going to be, every interval we are going to execute updateNews and this function is in charge of calling newsFeed.php through AJAX. newsFeed.php is in charge of query the database and responding with a json object that contains all the news information. Once updateNews() gets a response from newsFeed.php it will loop through the JSON object and add the content of the response to the div.

    Hope that makes sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a news website setup in PHP/MYSQL that's a bit old and
I'm building a new Intranet Portal with SharePoint 2007 that will have News, Site
I have written a script that takes an XML feed of some news, and
I have activity that parses XML feed (with news) and loads parsed data (text
I have a news feed where items in the feed are created from JSON
I have a PHP script (news-generator.php) which, when I include it, grabs a bunch
on my website I have a sidebar panel, which has two tabs that when
I have a blog that has a sidebar with a partial view in it
I have a site that allows a user to login using their facebook login
There is an app that displays news from the RSS feed. What should I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.