Jump to content

Recommended Posts

I have a page that I export divisions from a league one after each other to a text file.

I can get it to export the data but once I add the array_multisort some teams are placed in the wrong division.  It works fine for one division then I added the code following code so I can export each division in the league.  Can anyone see whats wrong with the array_mulitsort.

[code]
do
{


}


$defaultdivisionid++;
} while ($row_divisions = mysql_fetch_assoc($divisions));
[/code]


Complete Code

[code]

<?php session_start();

//Connect to the database and select used database
require('../dbconnect/config.php');
require('../dbconnect/dbconnect.php');

header ("Content-type: application/csv");
header ("Content-Disposition: inline; filename=$row_filename[name]_tables.txt");

do
{
// Column Headers
echo("Team\t");
echo("P\t");
echo("W\t");
echo("D\t");
echo("L\t");
echo("F\t");
echo("A\t");
echo("Pts\t\n");

// Get Match Teams for selected Division & Season.
mysql_select_db("$dbname", $dbconnect);
$query_get_teams = "
SELECT DISTINCT O.teamName AS name, O.teamID AS id
FROM leaguestats_teams O, leaguestats_matches LM
WHERE LM.matchSeasonID LIKE '$defaultseasonid'
AND LM.matchdivisionID = '$defaultdivisionid'
AND (O.teamID = LM.matchHomeID OR O.teamID = LM.matchAwayID)";
$get_teams = mysql_query($query_get_teams, $dbconnect) or die(mysql_error());
$row_get_teams = mysql_fetch_assoc($get_teams);
$totalRows_get_teams = mysql_num_rows($get_teams);
// End Get Match Teams for selected Division & Season.

// Start Loop and read teams in to Table.
$i = 0;
do
{
$team[$i] = $row_get_teams['name'];
$teamid[$i] = $row_get_teams['id'];
//$teamstatus[$i] = $row_get_teams['status'];

Get data to calculate points etc....

                      $points[$i] = $temp_points + ($wins[$i]*$for_win) + ($draws[$i]*$for_draw);
$pld[$i] = $homewins[$i]+$homedraws[$i]+$homeloses[$i]+$awaywins[$i]+$awaydraws[$i]+$awayloses[$i];

$diff[$i] = ($homegoals[$i] + $awaygoals[$i]) - ($homegoalsagainst[$i] + $awaygoalsagainst[$i]);

$i++;
} while($row_get_teams = mysql_fetch_assoc($get_teams)); // End Loop and read teams in to Table.

$qty = $totalRows_get_teams;


// Sort By Points
array_multisort($points, SORT_DESC, SORT_NUMERIC, $diff, SORT_DESC, SORT_NUMERIC, $goals_for, SORT_DESC, SORT_NUMERIC, $wins, SORT_DESC, SORT_NUMERIC, $goals_against, SORT_ASC, SORT_NUMERIC, $draws, $loses, $pld, SORT_DESC, SORT_NUMERIC, $team, $homewins, $homedraws, $homeloses, $awaywins, $awaydraws, $awayloses, $homegoals, $homegoalsagainst, $awaygoals, $awaygoalsagainst);

$i=0;
while($i < $qty)
{
echo "$team[$i]\t";
echo "$pld[$i]\t";
echo"$wins[$i]\t";
echo"$draws[$i]\t";
echo"$loses[$i]\t";
echo"$goals_for[$i]\t";
echo"$goals_against[$i]\t";
echo"$points[$i]\t";

$i++;

echo "\n";
}
echo "\n";

$defaultdivisionid++;
} while ($row_divisions = mysql_fetch_assoc($divisions));

?>


[/code]

Link to comment
https://forums.phpfreaks.com/topic/35259-array_multisort-export/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.