Jump to content

Recommended Posts

Maybe this is a mysql question, but I believe it's going to involve php to get it to work out correctly. My current query looks like this:

$query = mysql_query("
SELECT registrations.firstname, registrations.lastname, participants.q1, participants.q2, participants.q3, participants.q1s, participants.q2s, participants.q3s, participants.id, participants.cr
FROM events
INNER JOIN participants ON participants.eventid = $_GET[event]
INNER JOIN registrations ON registrations.id = participants.regid
WHERE events.id = $_GET[event] AND registrations.class = '$var'
ORDER BY LEAST(q1, q2, q3)") or DIE(mysql_error());

 

What we're looking at is q1 q2 q3. I need to take my results, and if all three values (individually not totaled together) are less than a specific set number, say 7.000, then it doesn't grab those results. Then I'll have to run a separate query right after it for those that are under 7.000. I know how to sum the 3 columns but that's not what I need. My entire script for this section is this:

 


$query = mysql_query("
SELECT registrations.firstname, registrations.lastname, participants.q1, participants.q2, participants.q3, participants.q1s, participants.q2s, participants.q3s, participants.id, participants.cr
FROM events
INNER JOIN participants ON participants.eventid = $_GET[event]
INNER JOIN registrations ON registrations.id = participants.regid
WHERE events.id = $_GET[event] AND registrations.class = '$var'
ORDER BY LEAST(q1, q2, q3)") or DIE(mysql_error());
if(mysql_num_rows($query)!=0){

$content .= "<h3><a name=\"$var\">$var</a></h3>";


$query2 = mysql_query("
SELECT * FROM participants INNER JOIN registrations ON registrations.id = regid WHERE class = '$var' && eventid = $_GET[event] LIMIT 1
") or DIE(mysql_error());
if(mysql_num_rows($query2)!=0){
	while($r2=mysql_fetch_array($query2))
	{
	$testcr = $r2[cr];
	if ($user->data['username_clean'] == admin OR $user->data['user_id'] == '461' OR $user->data['user_id'] == '205') {
if ($r2[cr] == '0'){
$content .= "<span style=\"float: right;\"><a href=\"index.php?page=ladders&lock=1&class=$var&event=$_GET[event]\">Lock $var</a></span>";
} elseif ($r2[cr] == 'ql'){
$content .= "<span style=\"float: right;\"><a href=\"index.php?page=ladders&unlock=1&class=$var&event=$_GET[event]\">Un-Lock $var</a></span><br /><span style=\"float: right;\"><a href=\"index.php?page=ladders&createp=1&class=$var&event=$_GET[event]\">Create Pairings</a></span>";
}
}
if ($r2[cr] != '0' AND $r2[cr] != 'ql'){
$content .= "<span style=\"float: right;\"><strong>Pairings Started</strong></span>";
}
	}
}


$rn = 0;
$pos = 1;
	while($r=mysql_fetch_array($query))
	{
	mysql_query("UPDATE participants SET `qp` = '$pos' WHERE id = '$r[id]'") or die(mysql_error());

	$t1 = $r[q1];
	$t2 = $r[q2];
	$t3 = $r[q3];
$rn++;

if ($r[q1] == x) {
$r[q1] = '';
} elseif (($t1 == $t2) OR ($t1 == $t3)) {
if (($t1 > $t2) OR ($t1 > $t3)) {
} else {
if ($user->data['username_clean'] != admin AND $user->data['user_id'] != '461' AND $user->data['user_id'] != '205') {
$r[q1] = "<font color=red>$r[q1]</font>";
}
}
} elseif (($t1 < $t2) && ($t1 < $t3)) {

if ($user->data['username_clean'] != admin AND $user->data['user_id'] != '461' AND $user->data['user_id'] != '205') {
$r[q1] = "<font color=red>$r[q1]</font>";
}


}




if ($r[q2] == x) {
$r[q2] = '';
} elseif (($t2 != $t1) && ($t2 == $t3)) {

if ($user->data['username_clean'] != admin AND $user->data['user_id'] != '461' AND $user->data['user_id'] != '205') {
$r[q2] = "<font color=red>$r[q2]</font>";
}

} elseif (($t2 < $t1) && ($t2 < $t3)) {

if ($user->data['username_clean'] != admin AND $user->data['user_id'] != '461' AND $user->data['user_id'] != '205') {
$r[q2] = "<font color=red>$r[q2]</font>";
}


}



if ($r[q3] == x) {
$r[q3] = '';
} elseif (($t3 < $t2) && ($t3 < $t1)) {
if ($user->data['username_clean'] != admin AND $user->data['user_id'] != '461' AND $user->data['user_id'] != '205') {
$r[q3] = "<font color=red>$r[q3]</font>";
}
}
if ($r[q1s] == x) {
$r[q1s] = '';
}
if ($r[q2s] == x) {
$r[q2s] = '';
}
if ($r[q3s] == x) {
$r[q3s] = '';
}



if (($user->data['username_clean'] == admin OR $user->data['user_id'] == '461' OR $user->data['user_id'] == '205') AND $testcr == '0') {
$content .= "<form action=\"index.php?page=ladders&event=$_GET[event]\" method=\"post\" name=\"ladders\">\n";
}

$content .= "<tr><td style=\"line-height: 10px; border: 1px solid #555; padding: 10px; border-top: 0px; border-left: 0px; text-align: right;\">$pos) $r[firstname] $r[lastname]</td><td style=\"line-height: 10px; border-bottom: 1px solid #555; border-right: 1px solid #555; padding: 10px; padding-left: 20px; padding-right: 0px;\" align=\"left\">";


if (($user->data['username_clean'] == admin OR $user->data['user_id'] == '461' OR $user->data['user_id'] == '205') AND $testcr == '0') {
$content .= "<input type=\"text\" maxlength=\"10\" name=\"q1\" value=\"$r[q1]\" size=\"4\" />";
if(!empty($r[q1s])){
$content .= " @ ";
} else {
$content .= " ";
}
$content .= "<input type=\"text\" maxlength=\"10\" name=\"q1s\" value=\"$r[q1s]\" size=\"4\" />";
} else {
$content .= "$r[q1]";
if(!empty($r[q1s])){
$content .= " @ ";
} else {
$content .= " ";
}
$content .= "$r[q1s]";
}

$content .= "</td><td style=\"line-height: 10px; border: 1px solid #555; padding: 10px; padding-left: 20px; padding-right: 0px; border-top: 0px; border-left: 0px; text-align: left;\" align=\"left\">";


if (($user->data['username_clean'] == admin OR $user->data['user_id'] == '461' OR $user->data['user_id'] == '205') AND $testcr == '0') {
$content .= "<input type=\"text\" maxlength=\"10\" name=\"q2\" value=\"$r[q2]\" size=\"4\" />";
if(!empty($r[q2s])){
$content .= " @ ";
} else {
$content .= " ";
}
$content .= "<input type=\"text\" maxlength=\"10\" name=\"q2s\" value=\"$r[q2s]\" size=\"4\" />";
} else {
$content .= "$r[q2]";
if(!empty($r[q2s])){
$content .= " @ ";
} else {
$content .= " ";
}
$content .= "$r[q2s]";
}


$content .= "</td><td style=\"line-height: 10px; border-bottom: 1px solid #555; border-right: 1px solid #555; padding: 10px; padding-left: 20px; padding-right: 0px; text-align: left;\" align=\"left\">";

if (($user->data['username_clean'] == admin OR $user->data['user_id'] == '461' OR $user->data['user_id'] == '205') AND $testcr == '0') {
$content .= "<input type=\"text\" maxlength=\"10\" name=\"q3\" value=\"$r[q3]\" size=\"4\" />";
if(!empty($r[q3s])){
$content .= " @ ";
} else {
$content .= " ";
}
$content .= "<input type=\"text\" maxlength=\"10\" name=\"q3s\" value=\"$r[q3s]\" size=\"4\" />";
} else {
$content .= "$r[q3]";
if(!empty($r[q3s])){
$content .= " @ ";
} else {
$content .= " ";
}
$content .= "$r[q3s]";
}
$content .= "</td>";

if (($user->data['username_clean'] == admin OR $user->data['user_id'] == '461' OR $user->data['user_id'] == '205') AND $testcr == '0') {
$content .= "<td> <input type=\"hidden\" name=\"hidden\" value=\"$r[id]\" /><input type=\"submit\" name=\"submitq\" value=\"Post\" /></td></tr></form>\n\n";
} else {
$content .= "<td></td></tr>\n\n";
}


$pos++;
	}









 

(may be missing a bracket or two I just copied a chunk)

 

 

 

edit: some extra notes - The three columns may not have something in them at all times. So if only q1 has been entered, and it's below 7.000 then it needs to be put to the bottom of the list. Basically here's an example of a correct order:

 

7.001

7.123

7.354

8.165

6.954

6.872

6.100

 

Ordering from least to greatest for those OVER 7.000, then the other way around for under it. Though it has to take in to consideration 3 columns and put them in order accordingly to the other columns in the whole thing.

Here's the page: http://outlawracing.com/index.php?page=ladders&event=1

Link to comment
https://forums.phpfreaks.com/topic/198914-help-with-how-to-order-results/
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.