Name: Anonymous 2010-07-03 7:48
I have some updating code, and I can't figure out how to remove the entry from the db if an error arises?
<?php
session_start();
require 'header.php';
?>
<?php
// Function for getting microtime in float (yes, from the PHP manual)
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
// Produce error page if we are not logged in
if (!auth())
{
?>
<div class="box">
<div class="header">
:: Need to log in ::
</div>
<div class="body">
This does not work unless you are logged in
</div>
</div>
<?php
}
else
{
?>
<div class="box">
<div class="header">
:: Mass update info ::
</div>
<div class="body">
The following were updated during this tick:
<br /><br />
<table class="infotable" <?php echo $iefix; ?>>
<tr><th>Character</th><th>Time</th><th>Status</th></tr>
<?php
// Get list of names
require 'database.php';
$namelist = $highscores->get_names();
$pertick = isset($_GET['count']) ? max(1, intval($_GET['count'])) : 5;
$count = count($namelist);
$pos = 0;
$total_time = 0;
if ($count > 0)
{
$name = isset($_GET['name']) ? $_GET['name'] : $namelist[0];
// Check that the name really exists in the database
if (($pos = array_search($name, $namelist)) === false)
{
trigger_error('Name not found in namelist!', E_USER_ERROR);
}
}
for ($i = 0; $i < $pertick && $pos + $i < $count; $i++)
{
$error = false;
$name = $namelist[$pos + $i];
$cache = get_highscore_charcache($name);
if (!$error)
{
$char = new rs_character($name, $cache);
$timer = microtime_float();
$error = !$char->load(false);
$timer = microtime_float() - $timer;
$total_time += $timer;
}
$upd = $error ? 'Failer' : 'Success';
echo ' <tr>' .
'<td class="left">' . display_rs_name($name) . '</td>' .
'<td>' . round($timer, 2) . ' sec</td>' .
'<td class="upd-' . $upd . '">' . $upd . '</td>' .
'</tr>' . chr(10);
flush();
}
?>
</table>
<br />
<?php echo $i; ?> updated /
<?php echo round($total_time, 2); ?> s /
<?php echo @round($total_time / $i, 2); ?> s per char.
</div>
</div>
<?php if ($pos + $i == $count) { ?>
<div class="box">
<div class="header">
:: Mass update finished ::
</div>
<div class="body">
Mass updating has finished.
</div>
</div>
<?php } else { ?>
<div class="box">
<div class="header">
:: Proceeding to next tick... ::
</div>
<div class="body">
<a href="massupdate.php?name=<?php echo $namelist[$pos + $i]; ?>&count=<?php echo $pertick; ?>">Click
here if you are not automatically forwarded</a>
</div>
</div>
<script type="text/javascript">
<!--
function forward(){
location.href="massupdate.php?name=<?php echo $namelist[$pos + $i]; ?>&count=<?php echo $pertick; ?>";
}
setTimeout('forward()', 2000);
// -->
</script>
<?php
}
}
?>
<?php
session_start();
require 'header.php';
?>
<?php
// Function for getting microtime in float (yes, from the PHP manual)
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
// Produce error page if we are not logged in
if (!auth())
{
?>
<div class="box">
<div class="header">
:: Need to log in ::
</div>
<div class="body">
This does not work unless you are logged in
</div>
</div>
<?php
}
else
{
?>
<div class="box">
<div class="header">
:: Mass update info ::
</div>
<div class="body">
The following were updated during this tick:
<br /><br />
<table class="infotable" <?php echo $iefix; ?>>
<tr><th>Character</th><th>Time</th><th>Status</th></tr>
<?php
// Get list of names
require 'database.php';
$namelist = $highscores->get_names();
$pertick = isset($_GET['count']) ? max(1, intval($_GET['count'])) : 5;
$count = count($namelist);
$pos = 0;
$total_time = 0;
if ($count > 0)
{
$name = isset($_GET['name']) ? $_GET['name'] : $namelist[0];
// Check that the name really exists in the database
if (($pos = array_search($name, $namelist)) === false)
{
trigger_error('Name not found in namelist!', E_USER_ERROR);
}
}
for ($i = 0; $i < $pertick && $pos + $i < $count; $i++)
{
$error = false;
$name = $namelist[$pos + $i];
$cache = get_highscore_charcache($name);
if (!$error)
{
$char = new rs_character($name, $cache);
$timer = microtime_float();
$error = !$char->load(false);
$timer = microtime_float() - $timer;
$total_time += $timer;
}
$upd = $error ? 'Failer' : 'Success';
echo ' <tr>' .
'<td class="left">' . display_rs_name($name) . '</td>' .
'<td>' . round($timer, 2) . ' sec</td>' .
'<td class="upd-' . $upd . '">' . $upd . '</td>' .
'</tr>' . chr(10);
flush();
}
?>
</table>
<br />
<?php echo $i; ?> updated /
<?php echo round($total_time, 2); ?> s /
<?php echo @round($total_time / $i, 2); ?> s per char.
</div>
</div>
<?php if ($pos + $i == $count) { ?>
<div class="box">
<div class="header">
:: Mass update finished ::
</div>
<div class="body">
Mass updating has finished.
</div>
</div>
<?php } else { ?>
<div class="box">
<div class="header">
:: Proceeding to next tick... ::
</div>
<div class="body">
<a href="massupdate.php?name=<?php echo $namelist[$pos + $i]; ?>&count=<?php echo $pertick; ?>">Click
here if you are not automatically forwarded</a>
</div>
</div>
<script type="text/javascript">
<!--
function forward(){
location.href="massupdate.php?name=<?php echo $namelist[$pos + $i]; ?>&count=<?php echo $pertick; ?>";
}
setTimeout('forward()', 2000);
// -->
</script>
<?php
}
}
?>