Mictotime to track delete on click

Hi All,

I was wondering whether someone could help, I would like to add microtime() to track how long it had taken to delete someone out of my simple database using PHP

as you can see below all my code can someone explain to me how we use microtime with delete? is it possible (even having the result output to a txt file would be handy too)

HTML

<table border=1 cellspacing="1" cellpadding="1">
<tr>
<th>
	Name
</th>
<th>
	Address
</th>
<th>
	Firstname
</th>

<?php include ("core/includes/Deletescript.php"); ?>
</tr>
</table>

Deletescript.php

<?php

$mysql_host = "localhost";
$mysql_username = "root";
$mysql_password = "";
$mysql_database = 'test';

$bd = mysqli_connect($mysql_host, $mysql_username, $mysql_password, $mysql_database) or die ("Could not connect to mysql");


$sql = "SELECT * FROM helloworld";
$records = mysqli_query($bd,$sql);


while($row = mysqli_fetch_array($records))
{
	echo "<tr>";
	echo "<td>".$row['name']."</td>";
	echo "<td>".$row['address']."</td>";
	echo "<td>".$row['firstname']."</td>";
	echo "<td><a href=index1.php?id=".$row['id'].">Delete</a></td>";
}

$sql = "DELETE FROM helloworld WHERE id='$_GET[id]'";

if(mysqli_query($bd, $sql))
	header("refresh:1; url=index1.php");
	
else
	echo "No

Current OUTPUT but I want to see the microtime be used once you delete a record out of the database


Name Address	Firstname
bob	London	       bob	            Delete
bob	bob	           bob	            Delete

All you need to do is call the function before the start of the operation, record the details in a variable, and then call it again after the operation, and display the difference.

$x = microtime();
// do your stuff here
echo microtime() - $x;

There seem to be a few issues with your code there - in particular the delete query looks as if it will try to run immediately after the list has been drawn. The header redirect will cause trouble too, because it comes at a point where you’ve already sent output to the browser - you’ll just get a “headers already sent” error.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.