...

View Full Version : PHP Random Number, Changed Weekly?



Golden_Eagle
03-05-2003, 02:40 PM
Strange title I know. But that is pretty much what I need! This is an file that will be included into my front page - You can specify the Files ID to show. But I need it to randomly change by itself every 24 hours.

I would like to change the value at -


<?php
$fileshowid=26
?>

part of this PHP script (near the top) to change to a number between 1 & 12824 once every 24 hours if possible.

I don't know if PHP programing is needed or if it can be sorted with javascript (or both).

Here is the script in question -

[code]
<?php
/*
paFileDB 3.1
2002/2003 PHP Arena
Written by Todd
todd@phparena.net
http://www.phparena.net
MOD written by Bekkel
Keep all copyright links on the script visible
Please read the license included with this script for more information.
*/
?>
<!--List here the file_id you want to show.. you can see the file's id in the adressbalk if you're looking at it in pafiledb -->
<?php
$fileshowid=26 ;
?>

<!--make sure these paths are right. it is set to the home dir.
place this file in the same directory as the file you're including this in.!! -->
<?php
require "./pafiledb/includes/mysql.php";
require "./pafiledb/includes/functions.php";

$pafiledb_sql->connect($db);
$config = $pafiledb_sql->query($db,"SELECT * FROM $db[prefix]_settings",1);
?>

<!--make sure the language path is right. it is set to the home dir. -->
<?php
require "./pafiledb/lang/$config[13].php";


$file = $pafiledb_sql->query($db, "SELECT * FROM $db[prefix]_files WHERE file_id = '$fileshowid'", 1);
$category = $pafiledb_sql->query($db, "SELECT * FROM $db[prefix]_cat WHERE cat_id = '$file[file_catid]'", 1);

$offset = ($config[7] * 3600) + $file[file_time];
$time = date("g:i A n/j/y", $offset);
if ($file[file_last] == 0) {
$last = "$str[never]";
} else {
$lastoffset = ($config[7] * 3600) + $file[file_last];
$last = date("g:i A n/j/y", $lastoffset);
}
$file[file_creator] = trim($file[file_creator]);
$file[file_version] = trim($file[file_version]);
$file[file_ssurl] = trim($file[file_ssurl]);
$file[file_docsurl] = trim($file[file_docsurl]);
if (!empty($file[file_creator])) { $creator = "<tr><td width=\"20%\">$str[creator]:</td><td width=\"80%\">$file[file_creator]</td></tr>"; }
if (!empty($file[file_version])) { $version = "<tr><td width=\"20%\">$str[version]:</td><td width=\"80%\">$file[file_version]</td></tr>"; }
if (!empty($file[file_ssurl])) {
if ($config[15] == 1) {
$ssurl = "<tr><td width=\"20%\">$str[scrsht]:</td><td width=\"80%\"><img src=\"$file[file_ssurl]\" border=\"0\"></td></tr>";
} else {
$ssurl = "<tr><td width=\"20%\">$str[scrsht]:</td><td width=\"80%\"><a href=\"$file[file_ssurl]\" target=\"_blank\">$file[file_ssurl]</a></td></tr>";
}
}
if (!empty($file[file_docsurl])) { $docsurl = "<tr><td width=\"20%\">$str[docs]:</td><td width=\"80%\"><a href=\"$file[file_docsurl]\" target=\"docs_$id\">$file[file_docsurl]</a></td></tr>"; }
$file[file_totalvotes] = $file[file_totalvotes] - 1;
if ($file[file_rating] == 0 or $file[file_totalvotes] == 0) { $rating = 0; } else {$rating = round($file[file_rating]/$file[file_totalvotes], 2); }
if ($file[file_license] == 0) {
$downloadlink = "pafiledb.php?action=download&id=$id";
}
if ($file[file_license] > 0) {
$downloadlink = "pafiledb.php?action=license&id=$file[file_license]&file=$id";
}
?>
<!-- if you don't want the file info just delete the line.
most things are plain html so you can easely change things. -->
<!-- table properties -->
<table width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#000000">
<!-- file name on top -->
<tr><td width="100%" colspan="2"><center><b><?php echo $file[file_name]; ?></b></center></td></tr>
<!-- file description.. the long one.. if you like short one change file_longdesc into file_desc -->
<tr><td width="20%"><?php echo $str[desc]; ?>:</td><td width="80%"><?php echo $file[file_longdesc]; ?></td></tr>
<!-- file creator the version and the urls IF you've filled them in -->
<?php echo "$creator\n$version\n$ssurl\n$docsurl"; ?>
<!-- file time added-->
<tr><td width="20%"><?php echo $str[date]; ?>:</td><td width="80%"><?php echo $time; ?></td></tr>
<!-- file last downloaded -->
<tr><td width="20%"><?php echo $str[lastdl]; ?>:</td><td width="80%"><?php echo $last; ?></td></tr>
<!-- file rating -->
<tr><td width="20%"><?php echo $str[rating]; ?>:</td><td width="80%"><?php echo $rating; ?>/10 (<?php echo "$file[file_totalvotes] $str[votes]"; ?>)</td></tr>
<!-- file downloads -->
<tr><td width="20%"><?php echo $str[dls]; ?>:</td><td width="80%"><?php echo $file[file_dls]; ?></td></tr>
<!-- file custom data if you added some -->
<?php
$result = $pafiledb_sql->query($db, "SELECT * FROM $db[prefix]_customdata WHERE customdata_file = '$id'", 0);
while ($custom = mysql_fetch_object($result)) {
$field = $pafiledb_sql->query($db, "SELECT * FROM $db[prefix]_custom WHERE custom_id = '$custom->customdata_custom'", 1);
$custom->data = trim($custom->data);
if (!empty($custom->data)) { echo "<tr><td width=\"20%\">$field[custom_name]:</td><td width=\"80%\">$custom->data</td></tr>"; }

}
?>
</table>

Any help would be much appreciated.

With Thanks

Golden_Eagle
03-05-2003, 06:22 PM
Randomising - Easy. Done that. :o



<?php
$number=rand(1,12000);
$fileshowid=$number;
?>


Only one more thing....

How do I make it only refresh this number every 24 hours?

Can this be adapted?


srand((double)microtime()*1000000);


Maybe changing microtime? :confused:

I wish I new PHP :(

Golden_Eagle
03-06-2003, 01:30 PM
Anyone?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum