在查询运行时显示加载栏和消息?

时间:2013-11-06 10:38:20

标签: php mysql sql

既然我在PHP(Using a PHP session variable within a MySQL file run in PHP)中运行大型.sql文件的困境得到了处理我想显示一个我做过的加载栏(.gif)和一条显示用户数据的消息正在上传到数据库,因为我不希望用户认为他们的浏览器没有加载页面(因为这个过程可能需要几分钟,具体取决于文件大小)。

<img src='includes/loadingbar.gif' width='128' height='15' alt=''/></p>
Uploading your school data into the database, please wait.
This process can take a while depending on your file size and connection.

上面是我想在查询运行时显示的图像和消息,但是在更新数据时我似乎无法通过白色加载屏幕。在查询之前,我已经尝试在查询之前回显消息,因为在PHP命令之前和之后放置了HTML代码 - 但我得到的仍然是这个邪恶的白屏。每次加载消息在查询完成之前都没有显示(具有讽刺意味),是否有一种方法可以在查询期间以我当前使用的格式显示,还是我必须转向其他编程语言?非常感谢!

编辑:

我试过在php标签之前和之后使用命令但是在查询完成之后它仍然无法运行:

<div id="message" div align="center"><img src="includes/loadingbar.gif" width="128"
 height="15" alt=""/>
<br />
Please wait while your school data is being uploaded into the database.
This can take a short while depending on your file size and connection.
</div>

<script type="text/javascript">
$(document).ready(function()
{$('message').show(); });
</script>


<?php   
session_start();

$page_title = 'SQLTest';
include ('includes/header.html');

require ('mldb_connect.php');
(etc...)

最后:

    if ($populateresult)
   {
   $replace = $_SESSION['path'].$_SESSION['CentreNo'].'_'.$_SESSION['School'].'_'
       .date('dmY_His').'.txt' ;

    rename ($path, $replace) ;
   }
 ?>

<script type="text/javascript">
$(window).load(function()
{$('message').hide();});
</script>

我做错了什么?

3 个答案:

答案 0 :(得分:1)

使用jQuery,您可以执行以下操作:

$("#imgId").show(); // Show loading image.

执行PHP脚本:

$.post( "your_script.php", function( data ) {
    // $("#imgId").hide(); // Hide loading image.
    window.location = "http://www.example.com"; // Redirect to URL.
});

更新: imgId是您图片的ID。例如:

<img src="image.png" id="imgId" />

答案 1 :(得分:0)

我可以告诉你两种不同的解决方案。

Sol 1 。当页面加载时触发查询:(没有Ajax):

在这种情况下,您可以使用一些jquery。

$(document).ready(function(){
  $('img').show();

});

$(window).load(function(){
      $('img').hide();
});

这将确保仅在加载程序图像隐藏时加载页面的所有元素。

sol 2

如果你想通过Ajax来做。触发触发Ajax的事件时显示图像,然后在Ajax的.success().done()隐藏图像加载器。

答案 2 :(得分:0)

虽然这是一个老问题,但可以在没有javascript的情况下完成。

需要&#39; sessions_start()&#39;。 转到包含please wait对话框并在头部转发器<meta http-equiv="refresh" content="1; url= http://example.com/myPage.php"

中的页面
相关问题