Nov 2, 2004, 22:43
...if you don't mind. I'm starting to dislike all those php-freak forums out there because there's alot of attitude. Since I know there's a few php coders 'round here - and everyone here is friendly, I'll try here first.
I need some help with multi-dimensional arrays... I've managed to bush-whack my way through creating one which works beautifully but I still can't quite wrap my head around how they work... The code currently dumps that array into a MySQL db, sorts it, and then spits it out - clearing the table at the end. Nothing is actually stored in the db, it's just a fancy calculator. Anyway, the number of queries is HUGE so I'd like to find a way to do it with arrays... Here's the function, annotated for your viweing pleasure...
If you's like to see what this code does, look here.
Thanks in advance...
I need some help with multi-dimensional arrays... I've managed to bush-whack my way through creating one which works beautifully but I still can't quite wrap my head around how they work... The code currently dumps that array into a MySQL db, sorts it, and then spits it out - clearing the table at the end. Nothing is actually stored in the db, it's just a fancy calculator. Anyway, the number of queries is HUGE so I'd like to find a way to do it with arrays... Here's the function, annotated for your viweing pleasure...
Code:
function results($divs, $pnames, $partynum, $seatnum) //$divs is a multi-array, $pnames is an associative array, $partynum & $seatnum are simple vars
{
for($pcount=0; $pcount<$partynum; $pcount++){
for($scount=0; $scount<$seatnum; $scount++){
$query=mysql_query("INSERT INTO pr (div, party, partyid) VALUES ('{$divs[$pcount][$scount]}', '{$pnames[$pcount]}', '$pcount')");
// this dumps the $divs array into the db along with identifying variables - keeping these together while sorting is the hard part
}
}
$query="select * FROM pr ORDER BY div DESC LIMIT $seatnum"; //this sorts the list and spits out the top X numbers
if ($r = mysql_query($query)) {
$counter=1;
while ($row = mysql_fetch_array ($r)) { //basically how do I creat this array with using MySQL...
//print $row['div']." ".$row['party']."<br>\n"; //USE THIS TO DISPLAY ORDERED LIST FOR VERIFICATION
if ($counter==1){
$winner=$row['partyid'];
}
$partyid=$row['partyid']; //these two lines count the number of times each identifier appears witha div number
$results[$partyid]++;
$counter++;
}
$results['divlimit']=$results[$winner];
}else{
mysql_error();
}
return ($results);
}
If you's like to see what this code does, look here.
Thanks in advance...
