1

Hi I am only new to php and I have already created a query that will insert data to mysql database but the clint wants to see a loading animation and not a progress bar to lessen the load in the browser. I checked in google on how to do it but I am not near to my objective. This is an excerpt in my php code:

foreach($line as $value)
        {
            $newline = explode(" ",$value[6]);
            $date = trim($newline[0]);
            $time = trim($newline[2]);
            $newtime = date("H:i",strtotime($time));

            try{
                $query = $con->prepare("INSERT IGNORE INTO temp_logs(EmpID, ValidDate, ValidTime)VALUES(:id,:date,:time)");
                $query->bindParam(':id',$value[2]);
                $query->bindParam(':date',$date);
                $query->bindParam(':time',$time);
                $query->execute();
                $row = $query->rowCount();
            }
            catch(PDOException $e){
                echo $e->getMessage();
                exit;
            }

Thanks in advance.

SilverRay
  • 331
  • 2
  • 7
  • 23
  • 1
    You will have to do this using ajax. php is a server side programming language and can not update the current dom. – Jerodev Dec 04 '15 at 07:23
  • 1
    PHP is a serverside scripting language, so you cannot do this with PHP only, you will need to do it in javascript. A way you can do it is making a javascript loading animation and use php's function called flush(). – Oliver Nybroe Dec 04 '15 at 07:24
  • Possible duplicate of [Jquery loading screen to cover a large mysql query via PHP?](http://stackoverflow.com/questions/12106829/jquery-loading-screen-to-cover-a-large-mysql-query-via-php) – Oliver Nybroe Dec 04 '15 at 07:27
  • I will try doing it in jquery/ajax and hope that it will work. – SilverRay Dec 04 '15 at 07:36
  • I agree with @Jerodev. You need to do it using AJAX. So that you can display loader on the top of you DOM element. – Khushang Bhavnagarwala. Dec 04 '15 at 09:17
  • ok I realize I need to separate the html upload page from php script upload page and bridge them with ajax and in that process call I wil add the loading animation during php script execution. – SilverRay Dec 05 '15 at 00:15

0 Answers0