Jump to content

Trouble sorting display data


xsgatour

Recommended Posts

Hi,

 

I'm hoping someone can enlighten me as to where my code has gone wrong.

 

Here's the situation:

 

On our Golf Leaderboard, when scores are submitted, the actual numerical scores are to be sorted from lowest numeric value to the highest, while the 'over/under par' values are sorted from highest to lowest. This works just fine when only TWO scores are submitted, and displayed.

 

Anything over 3 player scores, it reverses the sorting of the data stated above.

 

Here's the PHP file: (I consider this script 'short' - I hope it falls with the parameters mentioned by the staff)

 

<?php
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

require_once( $mainframe->getPath( 'front_html' ) );
require_once( $mainframe->getPath( 'class' ) );

$id = mosGetParam( $_REQUEST, 'cid', array(0) );
if (!is_array( $id )) {
$id = array(0);

}
switch($task) {

	case 'saveScores' :
	saveScores($option);
	break;

	case 'addScores' :
	editScores ($option, $id, $my);
	break;

	case 'viewScores' :
	viewScores ($option, $id);
	break;

	case 'listScores' :
	listScores($option, $my);
	break;

	case 'approveScores' :
	approveScores($option, $my);
	break;

	default:
	leaderBoard($option, $my);
	break;

}

function leaderBoard ($option, $my) {
global $database;
$database->setQuery("SELECT * FROM #__xsga_scores, #__xsga_tournament, #__users WHERE #__xsga_scores.t_id = #__xsga_tournament.t_id AND #__xsga_scores.p_id = #__users.id");
$rows = $database->loadObjectList();

HTML_xsgaapprove::leaderBoard($option, $rows, $my);

}

function approveScores ($option, $my) {
global $database;



$database->setQuery("SELECT * FROM #__xsga_approve
					WHERE p2 = '$my->id'
					OR p3 = '$my->id'
					OR p4 = '$my->id'");
$rows = $database->loadObjectList();
$i=0;
foreach ($rows as $row) {

$database->setQuery("SELECT * FROM #__xsga_tournament WHERE #__xsga_tournament.t_id='$row->t_id' LIMIT 1");
$t_names = $database->loadObjectlist();
$t_name[$i] = $t_names[0];

$database->setQuery("SELECT name FROM #__users WHERE id='$row->p1' LIMIT 1");
$p1 = $database->loadObjectlist();
$p1_name[$i] = $p1[0];

$database->setQuery("SELECT name FROM #__users WHERE id='$row->p2' LIMIT 1");
$p2 = $database->loadObjectlist();
$p2_name[$i] = $p2[0];

$database->setQuery("SELECT name FROM #__users WHERE id='$row->p3' LIMIT 1");
$p3 = $database->loadObjectlist();
$p3_name[$i] = $p3[0];

$database->setQuery("SELECT name FROM #__users WHERE id='$row->p4' LIMIT 1");
$p4 = $database->loadObjectlist();
$p4_name[$i] = $p4[0];

$i++;
}

HTML_xsgaapprove::approveScores($option, $my, $rows, $i, $p1_name, $p2_name, $p3_name, $p4_name, $t_name);

}

function listScores ($option, $my) {
global $database;

	$database->setQuery("SELECT * FROM
		#__xsga_scores, #__xsga_tournament
		WHERE #__xsga_scores.t_id = #__xsga_tournament.t_id
		AND #__xsga_scores.p_id = '$my->id'");
	$rows = $database->loadObjectList();

HTML_xsgaapprove::listScores($option, $my, $rows);
}

function editScores($option, $uid, $my) {
global $database;
	$row = new xsgaapprove($database);
	if($uid){
	$row -> load($uid[0]);	
	}
$database->setQuery("SELECT * FROM #__xsga_tournament");
$t_names = $database -> loadObjectList();

	if ($database -> getErrorNum()) {
	echo $database -> stderr();
	return false;
	}
$database->setQuery("SELECT * FROM #__users ORDER BY username ASC");
$p_names = $database -> loadObjectList();
	if ($database -> getErrorNum()) {
	echo $database -> stderr();
	return false;
	}
$database->setQuery("SELECT * FROM #__users WHERE #__users.id = '$my->id'");
$name = $database -> loadObjectList();
	if ($database -> getErrorNum()) {
	echo $database -> stderr();
	return false;
	}
HTML_xsgaapprove::editScores($option, $row, $t_names, $p_names, $name);
}
function saveScores ($option) {
global $database;
$row = new xsgaapprove($database);
$msg = 'Saved Scores';
if (!$row->bind( $_POST )) {
	echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
	exit();
}
	if (!$row->store()) {
	echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
	exit();
}
mosRedirect( 'index.php?option=com_xsga', $msg );
}

?>

 

Now, while i'm pretty sure the problem lies in the PHP file, for the life of me, I can't find it. :P

 

The page i'm speaking of is:

 

http://sevenfour.net/index.php?option=com_xsga&Itemid=65

 

Unfortunately, this weeks tourney just started today, so seeing only two IDENTICAL score posted really won't magnify the issue. ;) If you require to see the page in it's incorrect format, I'll be more than happy to post back once more scores are posted, which will be sometime today/tonight.

 

Your help in this matter would be EXTREMELY appreciated!

 

Thanks in advance.  :)

Link to comment
https://forums.phpfreaks.com/topic/75285-trouble-sorting-display-data/
Share on other sites

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.