www.webdeveloper.com
Results 1 to 2 of 2

Thread: news page

  1. #1
    Join Date
    Jan 2014
    Posts
    10

    Question news page

    first of all
    I`m new on this forum
    so if I creat this thread not In its place sorry!!!

    now the job!!!

    I`m creating news page with php

    in the nes.php I have this code

    $query = 'select * from news';
    mysql_query($query);

    and then I`m fetching info and creating echo statement with while loop

    everithis is working well..

    but if client will refresh the page
    it automaticaly going in DB and executing query again...

    my question is
    how to check if client is on the page and
    if after last visit is gone ex. 5 min
    page can execute query
    else
    it must echo this info that have in this time...

    I think you understand me!!!
    P.S. sorry for my bad English...

  2. #2
    Join Date
    Feb 2012
    Location
    Tallahassee, FL
    Posts
    280
    First off, for performance, stop using wild cards. Instead use some thing like:
    Code:
    SELECT id, title, content, date FROM news
    You'll probably want to store your return in a session so you don't have to make as many queries. Something like this may help:
    Code:
    <?php
    if(!isset($_SESSION)){
       session_start();
       $lastPull = 0;
    }else{
       $lastPull = $_SESSION['lastPull'];
    }
    //(I suggest MySQLI)
    $sqli = new mysqli(HOST,USER,PASS,DB);
    $currentTime = time();
    
    if(!isset($_SESSION['newsArray']) || ($currentTime - $lastPull) > 300){
       $getNews = "SELECT id, title, content, date FROM news";
       $exeGetNews = $sqli->query($getNews);
       $newsArray = $exeGetNews->fetch_array(MYSQLI_ASSOC);
       $_SESSION['newsArray'] = $newsArray;
    }else{
       $newsArray = $_SESSION['newsArray'];
    }
    
    while($row = $newsArray){
       //Do Stuff
    }

Thread Information

Users Browsing this Thread

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

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