Jump to content


Photo

coded table output


  • Please log in to reply
2 replies to this topic

#1 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 15 June 2006 - 03:23 PM

Not sure how to do this:

I have a query that creates a simply result in a table.

What I need is for the table to be color coded or some other identifiable way so you can tell which results are in the top 7.5% and which results are in the bottom 7.5%. You may get a different number of returns each time, so the math has to be dynamic...

some ideas I already have are:

1. do a count, calculate the number of records, then do three separate queries using LIMIT

2. do a count, and use some clauses for each row based on some math

or is there a better way?

Thanks for you suggestions

btw, here is the script as it stands...

$result2 = mysql_query("Select
surveyresults.TEAM_LEADER,
surveyresults.FNAME,
surveyresults.LNAME,
surveyresults.ID,
Avg(surveyresults.RATING) AS RATING
From
surveyresults
Inner Join survey ON surveyresults.ID = survey.ID
Where
survey.INACTIVE Not Like 'YES'
Group By
surveyresults.ID
ORDER BY
RATING ASC");
ECHO "<TABLE BORDER='1'>";
while ($row = mysql_fetch_array($result2)){
         ECHO "<TR><TD>".$row[3]."</TD><TD>".$row[2]."</TD><TD>".$row[1]."</TD><TD>".$row[4]."</TD></TR>";
}
ECHO "</TABLE>";




#2 poizn

poizn
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 15 June 2006 - 04:01 PM

Hey try this

$total_rows = mysql_num_rows($result2);
$row_num = 1;
while ($row = mysql_fetch_array($result2)){
$color = "#normal color"
if((100 * $row_num) / $total_rows < 7.5)
$color = "#color 1";
else if((100 * $row_num) / $total_rows > 92.5)
$color = "#color 2";
ECHO "<TR style="color:$color"><TD>".$row[3]."</TD><TD>".$row[2]."</TD><TD>".$row[1]."</TD><TD>".$row[4]."</TD></TR>";

$row_number ++;
}

hope this is ok :)

#3 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 15 June 2006 - 04:30 PM

that might have been easier... I went this way:
$result1 = mysql_query("Select
count( distinct surveyresults.ID)
From
surveyresults
Inner Join survey ON surveyresults.ID = survey.ID
Where
survey.INACTIVE Not Like 'YES'");
if ($row = mysql_fetch_array($result1)){
$i= $row[0];
}
$top=$i*.075;
echo $top;
echo"-";
$bottom=$i*.825;
echo $bottom;
$c=1;
ECHO "<TABLE BORDER='1'>";
$result2 = mysql_query("Select
surveyresults.TEAM_LEADER,
surveyresults.FNAME,
surveyresults.LNAME,
surveyresults.ID,
Avg(surveyresults.RATING) AS RATING
From
surveyresults
Inner Join survey ON surveyresults.ID = survey.ID
Where
survey.INACTIVE Not Like 'YES'
Group By
surveyresults.ID
ORDER BY
RATING desc");
ECHO "<TABLE BORDER='1'>";
while ($row = mysql_fetch_array($result2)){

         if($c<=$top)
             {echo "<tr bgcolor='#00ff00'>";}
         elseif($c>=$bottom)
             {echo "<tr bgcolor='#ff7777'>";}
         else
             {echo "<tr bgcolor='#ffffff'>";}

         ECHO "<td>".$c;
         $c++;
         echo "</td><TD>".$row[3]."</TD><TD>".$row[2]."</TD><TD>".$row[1]."</TD><TD>".$row[4]."</TD></TR>";
}
ECHO "</TABLE>";





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users