Page 1 of 1

Trouble with array

Posted: Thu Jul 13, 2006 12:29 am
by seodevhead
Hey guys... For some reason with the code below... the array $arrayThreadTimes is not being created correctly and populated correctly. I know it is something simple I am missing here. Perhaps you guys could take a look and tell me if I have something wrong with this code. Thanks a bunch!

Code: Select all

$start = 1152691200 + 18000;  ## 07/12/06 @ 8 am
$end = 1152813600 + 180000;    ## 07/13/06 @ 6 pm

$query = "SELECT COUNT(threadid) FROM thread";
$result = mysql_query($query);
$set = mysql_fetch_row($result);

$numThreads = $set[0];

$arrayThreadTimes = array();

for ($i = 0; $i < $numThreads; $i++)
{
	$randTime = rand($start, $end);  ## Add 1800 for US Eastern Time.
	
	while ($randTime > (1152747000+18000) && $randTime < (1152777600+18000))
	{
		$randTime = rand($start, $end);
	}
	
	$arrayThreadTimes['$i'] = $randTime;
		
}

sort($arrayThreadTimes, SORT_NUMERIC);
print_r($arrayThreadTimes);

Posted: Thu Jul 13, 2006 12:51 am
by Benjamin
Most likely $numThreads is 0. Might want to muck with the query a little bit...

Something like this might work..

Code: Select all

$query = "SELECT COUNT(threadid) as `total` FROM thread";
$result = mysql_query($query);
$set = mysql_fetch_assoc($result);

$numThreads = $set['total'];

Posted: Thu Jul 13, 2006 2:53 am
by Weirdan

Code: Select all

// perhaps
$arrayThreadTimes['$i']
// should be 
$arrayThreadTimes[$i]

Posted: Thu Jul 13, 2006 2:55 am
by Benjamin
Oooh good catch!