SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Jan 2014
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    progress bar problem

    Hi I would love to display a progress bar when inserting data from one mysql table from another mysql table.

    The examples I keep coming across are particularly concerned with progress bars that are displayed when uploading data from a form and displaying it on another form and I just can't seem make the current code I have to display the bar eventhough the query is executed successfully.

    Your help in this regard will be highly appreciated.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,494
    Mentioned
    164 Post(s)
    Tagged
    1 Thread(s)
    Hi kgizzy, welcome to the forums,

    I suppose it might be possible to do, but why?

    Database INSERT queries happen server-side and usually run so fast that for all intents and purposes they're "instant". Even major database manipulalation runs fairly fast.
    Any progress bar would likely "blink" and even then passing the info back via an HTTP request would take longer than the INSERT took to run.
    IMHO it would be better to send back a simple "success" type of message.

    Are you sure you shouldn't be looking into optimizing your tables and queries instead?

  3. #3
    SitePoint Member
    Join Date
    Jan 2014
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Mittineague

    The thing is I should have a progress bar for every operation that occurs on my web based application and the starting point is having a progress bar for a mysql query.

    Displaying the progress bar seems to be a mission impossible but everything else works perfectly.

    Thanks for taking the time to offer your helping hand its much appreciated.

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,494
    Mentioned
    164 Post(s)
    Tagged
    1 Thread(s)
    It's not impossible, just how do you show the progress for something that typically takes a mere fraction of a second, or only a few seconds at most?

    Often the "bottle necks" in a site visitors experience have more to do with the transfer of data via HTTP requests. eg. heavy weight img, swf, files.

    Though sometimes slowdown or even hang can be a result of poor code.

    Maybe what you are looking for is Benchmarking? Maybe this recent thread will give some ideas? http://www.sitepoint.com/forums/show...-32-bit-system

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Location
    Singapore
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any progress bar component will need to be given the update percentage from the process being run. What does the SQL statement look like that is performing the insert? If it is inserting a lot of rows perhaps you could break it in to chunks and report the progress after each chunk?

    This would most likely slow the overall insert but would give you the progress if the usability factor was worth it.

  6. #6
    SitePoint Member
    Join Date
    Jan 2014
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Guys

    @Mittineague my code already has the duration of the whole execution process which works perfectly its just one aspect of my project that doesn't seem to work which is the progress bar. My script when executed should display the progress bar and the total time taken to execute the query. At the moment the query does work and the total time taken is functional.

    @Jordan Windebank here's the code snippet:

    Code:
    <?php
    
    
         $time_start = microtime(true);
    
        $mysqlserver = "localhost"; 		
        $user = "root";
        $pass = "";
        $db = "Profusion";
     
        $link = mysql_connect( "$mysqlserver", $user, $pass );
        if ( ! $link )
        die( "Couldn't connect to MySQL" );
        //print "Successfully connected to server<P>";
     
        mysql_select_db( $db )
        or die ( "Couldn't open $db: ".mysql_error() );
        //print "Successfully selected database \"$db\"<P>"; 
     
        $result3=mysql_query("INSERT INTO dest_table.create_info SELECT * from Profusion.source_cdr") or die(mysql_error());
        $progress=mysql_affected_rows();
    
        $time_end = microtime(true);
        $time = $time_end - $time_start;
    
        echo  "Total time taken :"." ".round($time,6) . " s";    
    
         ?>
    There are 28 rows to be inserted in the table so it's not really big.

    I am trying to utilize the article written by TIm ad he passes the progress bar to a form unfortunately. link below

    http://www.sitepoint.com/tracking-up...nd-javascript/

  7. #7
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,494
    Mentioned
    164 Post(s)
    Tagged
    1 Thread(s)
    Yes, but that article is about uploading (the aforementioned HTTP requests) not database profiling.

    Is this something you want only for yourself or for every user?

  8. #8
    SitePoint Member
    Join Date
    Jan 2014
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am running a mini application here at work so its currently for myself. I here what you are saying.

    Thanks alot I'll try and re-direct my approach. Your efforts are highly appreciated.

  9. #9
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,909
    Mentioned
    96 Post(s)
    Tagged
    0 Thread(s)
    Please be aware that the mysql_* extension is now deprecated as of the current version of PHP and will very likely be removed from the next 5.x version and will likely not be in PHP 6.x (when it eventually is released). You should migrate over to either the mysqli_* extension or to PDO. PDO is a better choice as it doesn't tie you down so much to a particular database server software.

    Once you have migrated you should use Prepared Statements to prevent SQL Injection attacks. Have a read of this article from the PHP manual, it shows how to use prepared statements with PDO and also explains the principle.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator


Tags for this Thread

Bookmarks

Posting Permissions

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