I think maybe global.php doesn't work right when included inside a function. You could do this:
PHP Code:
<?php
define('CSRF_PROTECTION', true);
require_once('./global.php');
function sotw_number($dummy) {
global $vbulletin;
$result = $vbulletin->db->query("SELECT id FROM cotw_sotw_time_end ORDER BY id DESC LIMIT 1");
$row = mysql_fetch_row($result);
echo $row[0];
}
sotw_number(true);
?>
(BTW, I had a feeling the code I posted last night was undoing something you were trying to do

)