473,406 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Display mysql records from database 1 by 1

3
In my PHP script, I have a basic mysql call :


Expand|Select|Wrap|Line Numbers
  1. $sql = "SELECT * FROM ...";
  2. $req = mysql_query($sql) or die();
  3.  
  4. while($data0 = mysql_fetch_assoc($req)) {
  5.   //some update stuff here
  6.   echo "Important information about update...";
  7. }
  8.  
I have +7000 records in my database (and growing), so i'd like to show the update process result 1 by 1 and not showing them when script is finished.

Could you please tell me how to do this?

Thank you!
Oct 28 '12 #1
6 2962
Rabbit
12,516 Expert Mod 8TB
Do you mean 1 record per page with a next record button/link? You'll want to look into pagination.
Oct 29 '12 #2
A973C
3
Thank you for your answer Rabbit!

I'm searching a way to fire my ECHO after each record, a live update. So i don't want to have to wait the end of the script (can take several hours).
Oct 29 '12 #3
Rabbit
12,516 Expert Mod 8TB
You can't do that with PHP alone. You will have to use AJAX and have it retrieve one record at a time. Most people just use pagination in this scenario.
Oct 29 '12 #4
A973C
3
Pagination need a human action. With 7000 records and ~20 seconds per record, it would need so much time!

Do you have a link/code snippet to share for ajax use, please?
Oct 29 '12 #5
Rabbit
12,516 Expert Mod 8TB
Here is a link to an AJAX tutorial.

Pagination puts much less of a strain on the server by showing a subset of the records at a time. Whereas what you're attempting to do will bombard the server with constant requests over many hours. Having just a few people on at once could bring the server to a crawl.

You said 7000 records? That should not take anywhere near a few hours to return data. That shouldn't even take a few seconds to return. I suspect that your query is unoptimized and you would be better served by fixing your query instead of working around the inordinate amount of time it takes.

We have queries with millions of rows that return quicker than that.
Oct 29 '12 #6
Claus Mygind
571 512MB
Looks to me you already have it streaming out. Here is another method, where you fetch all into an array and then stream out the array, if your computer has enough memory. Don't know how much data you have in each record.

Expand|Select|Wrap|Line Numbers
  1. $cr = mysqli_fetch_all ( $result , $resulttype = MYSQLI_ASSOC );
  2.  
  3. $cCnt = $result->num_rows;
  4.                             for ($n=0; $n < $cCnt; $n++) 
  5. {
  6.  
  7. $c = $cr[$n];
  8.  
  9. //do your processing and echoing here.
  10.  
  11. }
  12.  
  13.  
Nov 2 '12 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Antoni | last post by:
Hello, I wondered if anyone could offer some guidance, I trying to write a php script to connect to a database, and display the records in a table. I found the code here in a php4 text, and...
0
by: Sohail Hasan | last post by:
Hi All, I want to bring back my mysql original database as well as root GRANTS as was during the installation because i installed an application that modified my root GRANTS and now I am not...
5
by: Jack | last post by:
Hi, I need to build a asp page where it would serve as a data entry record page as well as display page for records saved. This page should also allow editing of records that has been saved. ...
1
by: ponvijaya | last post by:
I want to take back up of records in My MySql Database I want to convert the records into csv file and store in a location. If needed I want to import it to the same database.. I need to...
1
by: mramsay | last post by:
Hi there, I have a dynamic hyperlink Baseball. When the user select the hyperlink they are redirected to another page. After that I want to display information on the page from my linkstbl. ...
48
by: mirianCalin | last post by:
i am doing a site for appliance center.. i need to display all the products that the company offers, but my problem is that i cant display ALL the images in my database.. the first entry on the...
4
by: Mubs | last post by:
Hi all, I have a website set up using database, what i want to achieve is, i want a user to enter their number and then the database to display the records for only that number they...
3
by: Coll | last post by:
I have a form that had been setup with a combo box. You'd select a value from the combo box and a query would open and display matching records. I now need to remove the combo box and set up a text...
2
by: puneetmca | last post by:
hi i m new in php.... i want to generate a report of my database records having field names FirstName ,LastName and Age in student table and test database.....and i want to display these records in...
1
by: reymon | last post by:
<?PHP //THIS IS MY DB CLASS CONNECTION class db { private $hostname; private $username; private $password; private $database; private $connect; private...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.