Currently i have a script ran via cron, which does what i want, but according to my host its running around 290,000,000 a day, which i don't want
This is the scripts
cron.php
<?php
include "/home/calona/calona/includes/db_config.php";
// Get all users
$csql = "SELECT ID FROM users";
$cresult = mysql_query($csql) or die(sql_error($csql));
while($cron = mysql_fetch_array($cresult)) {
// Run the eggs update;
include "/home/calona/calona/includes/function_eggs.php";
}
?>
function_eggs.php
<?php
// Set up variables
$common = $num = $count = 0;
$uncommon = 80;
$rare = 90;
$urare = 96;
$ids = array();
// Set the user id
$uid = $cron['ID'];
// Get the eggs
while($count < 5)
{
$num = rand(1,100);
$type = '';
if($num < $uncommon) // Common
{
$type = 'Common';
}
elseif($num < $rare) // Uncomon
{
$type = 'Uncommon';
}
elseif($num < $urare) // Rare
{
$type = 'Rare';
}
else // Ultra-Rare
{
$type = 'Ultra-Rare';
}
$sql = "SELECT c.ID
FROM creatures AS c
RIGHT JOIN user_access AS u ON u.cid = c.ID AND u.uid = '".$uid."'
WHERE c.rarity = '".$type."'
AND c.type = 'Egg'
ORDER BY RAND( )
LIMIT 1";
$result = mysql_query($sql) or die(sql_error($sql));
while($row = mysql_fetch_array($result))
{
$ids[] = $row['ID'];
$count++;
}
}
// Insert these into the database
$sql = "INSERT INTO eggs (uid, id1, id2, id3, id4, id5) VALUES
(".$uid.", ".$ids[0].", ".$ids[1].", ".$ids[2].", ".$ids[3].", ".$ids[4].")";
mysql_query($sql) or die(sql_error($sql));
?>
What this is supposed to do is select 5 random creatures that the user has access to depending on the types
The problem occurs if the user doesn't have any of the specific type, it reruns the query until it gets 5
Can any one help me improve this