I've sort of got something so far but it seems like my while loop isn't working correctly. Perhaps it's a syntax error? Maybe you could shed some light?
Code: Select all
$q="SELECT COUNT(*), horseID, total FROM enteredHorses";
$r = mysqli_query ($dbc, $q) or trigger_error(mysqli_error($dbc));
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
$count = $row['COUNT(*)'];
$horse_id = $row['horseID'];
$total = $row['total'];
for ($counter = 1; $counter <= $count; $counter += 1) {
$i = 0;
$id[$i] = $horse_id;
$total[$i] = $total;
$i = $i+1;
}
} //end while
array_multisort($total, SORT_DESC, $id);
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
for ($counter = 1; $counter <= $count; $counter += 1) {
$i = 0;
$place = '1';
$q = "INSERT INTO enteredHorses (place) VALUES ('$place') WHERE horse_id='$id[$i']'";
$r = mysqli_query ($dbc, $q) or trigger_error(mysqli_error($dbc));
$i = $i + 1;
$place = $place + 1;
}
}