Jump to content

Need more effecient way of writing working code.


JSLayton

Recommended Posts

How could I accomplish this same task WITHOUT involving MySQL??  I'm assuming I can use either OOP or Arrays, but not sure the best way to go about it.  PLEASE HELP!!

 

	$query = "TRUNCATE TABLE `temp_results_table`";
mysql_query($query);

$query = "SELECT * FROM coaches WHERE sport='".$sport."' AND league='".$league."'";
$results = mysql_query($query);
while ($row = mysql_fetch_assoc($results)) {
	$query = "INSERT INTO temp_results_table (teamname, wins, losses, pointdiff) VALUES ('".$row['name']."', 0, 0, 0)";
	mysql_query($query);
}

$query = "SELECT * FROM results WHERE sport='".$sport."' AND league='".$league."' AND (awayscore IS NOT NULL AND homescore IS NOT NULL)";
$results = mysql_query($query);
while ($row = mysql_fetch_assoc($results)) {
	if ($row['awayscore'] < $row['homescore']) {
		$winner = $row['home'];
		$loser = $row['away'];
		$pointdiff = $row['homescore'] - $row['awayscore'];
	} else {
		$winner = $row['away'];
		$loser = $row['home'];
		$pointdiff = $row['awayscore'] - $row['homescore'];
	}

	$query = "UPDATE temp_results_table SET wins = wins + 1, pointdiff = pointdiff + ".$pointdiff." WHERE teamname = '".$winner."'";
	mysql_query($query);
	$query = "UPDATE temp_results_table SET losses = losses + 1 WHERE teamname = '".$loser."'";
	mysql_query($query);
}

$query = "SELECT * FROM temp_results_table ORDER BY wins DESC, losses ASC, pointdiff DESC";
$results = mysql_query($query);
while ($row = mysql_fetch_assoc($results)) {
	echo $row['teamname']."  ";
	echo $row['wins']."  ";
	echo $row['losses']."  ";
	echo $row['pointdiff']."  ";
	echo "<br />";
}

Your request doesn't make any sense. MySQL is a database, which looking at your script is where your data is coming from. If you don't want to use MySQL pick any other database out there or alternative use a flat file system (not recommended) for your data storage.

What I meant was the end of the code, where I was putting the code into a temp database table only to pull it back out.  I was using it for sorting purposes because I knew how to make it work.  I was able to get it into an array which I then sorted using array_multisort.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.