homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

List results as they happen

 2:53 pm on Jun 29, 2006 (gmt 0)

Is it possible to list UPDATE or INSERT results as they are entered into the database with PHP, rather than echoing out the whole thing at the end.

Added product one....
Added product two....
Added product three...

As opposed to:
Your products have been updated and we have added
product one....
product two....
product three...

Is javascript required?



 3:27 pm on Jun 29, 2006 (gmt 0)

I guess it would depend on whether or not your are executing multiple queries. If so, then you can echo the progress out after each successful query. If not, then echoing the progress at the end seems best. I wouldn't go out of your way to achieve this, though; you may lose some efficiency. In the end, it will pretty much look the same to the viewer.

Good luck!


 5:16 pm on Jun 29, 2006 (gmt 0)

Thanks for replying.
Its just on a long query the user would have to sit there and wait until the whole thing has completed.
For me, from a usability point of view this is not a good thing as the user should be informed of what is going on as it happens. It also makes identifying problems easier, say with the import of a csv into mysql.

Not sure if I understand you correctly regarding echoing multiple queries out one at a time as I have never been able to achieve this when the queries are within a single page?

Any pointers would be much appreciated.


 6:51 pm on Jun 29, 2006 (gmt 0)

>>It also makes identifying problems easier
For this, I would suggest using mysql_error [us2.php.net] to identify any problems. If the query returns NULL, then you can account for that too.


 8:01 pm on Jun 29, 2006 (gmt 0)

What I meant was that if the results of a INSERT were echoed to the screen as they happened for say a 700 row csv import it would be very easy to see where the error had occured.
Mysql_error as a form of trapping is ok if you build your own error reporting system, but can mean absolutely nothing to an end user of system.

Does anyone know a way of echoing results as they are inputted?


 4:10 am on Jun 30, 2006 (gmt 0)

If you post the code specifically for the db insert than I would be able to help you a little more. I'm still unsure whether or not you are inserting everything at once or individually. Post some code and we'll get it working one way or another ;)


 9:33 pm on Jul 1, 2006 (gmt 0)

Not sure if this is going to help? but here you go.

Query within a for loop:

for($i=1; $i<count($contents); ) {

$query = "UPDATE products SET price = $price WHERE model = '$checkmodel'";
mysql_query($query) or die(mysql_error());
echo 'Updated Price of Model: <strong>'. $checkmodel.'</strong> To <strong>'.$price.'</strong><br>';



 4:51 pm on Jul 4, 2006 (gmt 0)

$price and $checkmodel have to be changed within the loop in order for mulitiple records to be updated.


 8:49 am on Jul 5, 2006 (gmt 0)

Sorry but we are going a bit off topic here.
I purposely omitted code after the for loop because it is not relevant to the question?

Anyone know a way of echoing results to the screen as they are inputted to the database?



 11:00 am on Jul 5, 2006 (gmt 0)

I put the following function into scripts that I want to have output as they go.
function flush_echo($string="")
echo $string;

And then call is after the update - flush_echo('Table 123 updated...');


 2:36 pm on Jul 5, 2006 (gmt 0)

What you have will work to show what stage you are in, but it will not work correctly if one of the queries do not successfully execute. For this, I would do something like:

$count = count($content);
for($i=1; $i<$count; $i++) {

$query = "UPDATE products SET price = $price WHERE model = '$checkmodel'";
$update = mysql_query($query) or die(mysql_error());
if($update) {
echo 'Updated Price of Model: <strong>'. $checkmodel.'</strong> To <strong>'.$price.'</strong><br>';
else {
echo '<b>DID NOT UPDATE</b>';
//change $price and checkmodel here

For other type of SQL statements, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

Good luck. Sorry about my last post ;)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved