Goodies Depot

Web Resources, HTML, SEO, AJAX, PHP, ERP, SAP, Microsoft Dynamics and latest IT Goodies.

Archive for the ‘PHP’ Category

Analyzing PHP Performance: PHP Quick Profiler

Posted by admin On September - 3 - 2009

w248h220_php-logoFirebug is the most popular tool for analyzing HTML, CSS & JavaScript based webpages. Now, there is PHP Quick Profiler (PQP), which can be called as Firebug for PHP.

It is specially focused on analyzing the performance of PHP codes. With a beautiful interface, PQP can:

  • log memory usage
  • display the number & sizes of included files
  • show page execution times
  • log database queries

PHP Quick Profiler

PHP Quick Profiler is not a plug & play solution as every project may have a totally different structure. But, by following the setup information & the example provided, it is easy to integrate.

To see how functional it is, you can check the demo.

Dynamic Drag’n Drop With jQuery And PHP

Posted by admin On April - 9 - 2009

ajax1Jquery Drag’n drop generally looks hard-to-apply but it is definitely not by using JavaScript frameworks. Here is, how it is done by using jQuery & jQuery UI:

jQuery Drag'n Drop

The Database:

We create a simple database as below:

jQuery Drag'n Drop Database

The most important column in the database is recordListingID which shows us the order of the records.

This feature can be applied to any table by adding such a column to it.

The HTML:

We’ll be using an unordered list that is generated from a PHP query that lists the items according to the recordListingID value mentioned above.

Here it is:

</p>
<div id="contentLeft">
<ul>
    <li id="recordsArray_&lt;?php echo $row['recordID']; ?&gt;">&nbsp;</li>
</ul>
</div>
<p>

The JavaScript:

We will be using jQuery UI’s sortable plugin.

 <script type="text/javascript">
$(document).ready(function(){ 

	$(function() {
		$("#contentLeft ul").sortable({ opacity: 0.6, cursor: 'move', update: function() {
			var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
			$.post("updateDB.php", order, function(theResponse){
				$("#contentRight").html(theResponse);
			});
		}
		});
	});

});
</script>

We made the unordered list inside #contentLeft a sortable item, used the serialize function of jQuery to create the array and posted it to updateDB.php.

The PHP:

After posting the array of “new order of the items” to updateDB.php, we must run a query to update our database that will reflect the last positions of every item:

<?php
require("db.php");

$action 				= $_POST['action'];
$updateRecordsArray 	= $_POST['recordsArray'];

if ($action == "updateRecordsListings"){

	$listingCounter = 1;
	foreach ($updateRecordsArray as $recordIDValue) {

		$query = "UPDATE records SET recordListingID = " . $listingCounter . " WHERE recordID = " . $recordIDValue;
		mysql_query($query) or die('Error, insert query failed');
		$listingCounter = $listingCounter + 1;
	}

	echo '<pre>';
	print_r($updateRecordsArray);
	echo '</pre>';
	echo 'If you refresh the page, you will see that records will stay just as you modified.';
}
?>

You can see that this is the easiest part. We handled the array as $updateRecordsArray and used it inside a for each statement.

With a new variable named $listingCounter, while the for each statement runs, we have updated the values of recordListingID column of every item in the database with $listingCounter values. And that’s it.

Free PHP Uptime Monitor Script: phpWatch

Posted by admin On April - 6 - 2009

ajax1Free PHP Uptime Monitor Script

PhpWatch is a free PHP uptime monitoring script that can watch unlimited number of websites and send notifications via e-mail or SMS (for US phones).

PhpWatch complete with an Ajaxed interface, new monitors & notifications can be easily configured. And, once the cron job / scheduled task -that pings the servers in desired time intervals- is set, the script is awesome and ready to go.

phpWatch also offering an API which lets other applications to query the monitored services, get the statistics and use the notification system for sending SMS and e-mail alerts.

Thursday, March 11, 2010