0

I have a website that is running php/MySQL to query and return results. The result set is over 40,000 and the query is getting slower. I want to find a simple way to display a loading image while the page builds. I can do it with any page running JavaScript but I assume since php is server side I need to handle the loading differently.

I see that AJAX has a load() function where I can call the php page and presumable show a loading image while the request is loading. Is that the best way? I can't believe that there aren't lots of example scripts floating around since this has to be a very common problem.

3
  • why do you need to send 40,000 results at one time? Sounds like you need to expand on AJAX useage and send data on demand Commented Jan 13, 2013 at 14:21
  • 1
    "this has to be a very common problem" It's not very common to returns 40,000 results. Commented Jan 13, 2013 at 14:23
  • Yeah, I guess I should have said, there are 40,000 people in my database now and I am running stats on those people. So, not 40,000 returns - the stats are run against 40,000 entries in the database. So, the query takes about 20 seconds. Commented Jan 13, 2013 at 14:53

2 Answers 2

4

Are you using an AJAX request to do this? If so, it's as simple as using JavaScript to display an image when you send the request, then hide it again upon success/error. You can just keep an <img> tag around with "display: none" and turn it on/off as needed.

If you aren't using AJAX, then this will be impossible, as the page does not exist until the query is completed.

On a side note: it's incorrect to say that "AJAX has a load() function". AJAX is not a code base or a library, it is a technique. Perhaps you mean jQuery.ajax, or some other library?

Sign up to request clarification or add additional context in comments.

1 Comment

No, the request is done with php mysqli. I have never used AJAX or jquery - hence the incorrect terminology. I really just want to display a loading image while my php code runs.
0

You got to use Ajax, i reckon Loading data from form into MySQL with PHP and AJAX will be useful and follow the jQuery API for Ajax reference

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.