Can someone help me out with my code. Its a bit of a mess.
I've been writing a program to sort elements in an SQL table by first dividing them by a certain key, then cutting the table in half, then sorting by a different key, dividing by half again, sorting again.. etc. There are four different keys. I'm a bit new to PHP, but I know how to do this in java and C++. Pretty much I've been trying to use associative, two deminsional arrays but its not working out to well. I get this error:
Parse error: syntax error, unexpected T_DOUBLE_ARROW on line 113
I've pointed out the place where I get the error. There is much more to the file than I'm going to post (because its a huge file and the rest works for sure). If you see any values you don't see assigned, assume they are valid.
Code:
//Establish link to database
$link = mysql_connect($dbhost, $dbusername, $dbpass)
or die("Failed to connect to database.");
print "Connected to database<br>";
//Select the database
$selected = mysql_select_db($dbname, $link)
or die("Could not select the database.");
//Get number of rows
$count = mysql_query('SELECT COUNT(host_id) FROM rate_hosts');
//Prepares to sort and divide by 2
$desired = (int) $count/2;
$hosts[$desired - 1];
$results = mysql_query("SELECT * FROM rate_hosts ORDER BY '$first' DECS;");
print 'working';
$i = 0;
//start sorting
while($row = mysql_fetch_array( $result ) and $i < $desired)
{
$hosts[$i] = $row[$second] => $row; //I GET THE ERROR HERE
$i++;
}
$desired = (int) $desired/2;
if($desired > 1)
{
krsort($hosts);
$index = 0;
foreach ($hosts as $key => $val)
{
$hosts[$index] = $val;
$index++;
}
$temp[$desired];
for($j = 0 ; $j < $desired; $j++)
{
$temp[$j] = $hosts[$j][$third] => $hosts[$j];
}
$hosts = NULL;
$hosts = $temp;
$desired = (int) $desired/2;
if($desired > 1)
{
print '.';
krsort($hosts);
$index2 = 0;
foreach($hosts as $key => $val)
{
$hosts[$index2] = $val;
$index++;
}
$temp2[$desired];
for($p = 0 $p < $desired; $p++)
{
$temp[$p] = $hosts[$p][$fourth] => $hosts[$p];
}
$hosts = NULL;
$hosts = $temp;
$desired = (int) $desired/2;
if($desired > 1)
{
print '.';
krsort($hosts);
$index3 = 0;
foreach($hosts as $key => $val)
{
$hosts[$index3] = $val;
$index++;
}
}
}
}
print '.<br>';
$final[3];
for($f = 0; $f < 3; $f++)
{
if($hosts[$f] != NULL)
{
$final[$f] = $hosts[$f];
}
}
for($counter = 0; $counter < 3; $counter++)
{
print $final[$counter][1];
}
//open connections are bad.
mysql_close($link);
print "<br>Connection to database closed.";
|