AV1611 Posted June 15, 2006 Share Posted June 15, 2006 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 LIMIT2. do a count, and use some clauses for each row based on some mathor is there a better way?Thanks for you suggestionsbtw, here is the script as it stands...[code]$result2 = mysql_query("Selectsurveyresults.TEAM_LEADER,surveyresults.FNAME,surveyresults.LNAME,surveyresults.ID,Avg(surveyresults.RATING) AS RATINGFromsurveyresultsInner Join survey ON surveyresults.ID = survey.IDWheresurvey.INACTIVE Not Like 'YES'Group Bysurveyresults.IDORDER BYRATING 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>";[/code] Link to comment https://forums.phpfreaks.com/topic/12071-coded-table-output/ Share on other sites More sharing options...
poizn Posted June 15, 2006 Share Posted June 15, 2006 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 :) Link to comment https://forums.phpfreaks.com/topic/12071-coded-table-output/#findComment-45957 Share on other sites More sharing options...
AV1611 Posted June 15, 2006 Author Share Posted June 15, 2006 that might have been easier... I went this way:[code]$result1 = mysql_query("Selectcount( distinct surveyresults.ID)FromsurveyresultsInner Join survey ON surveyresults.ID = survey.IDWheresurvey.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("Selectsurveyresults.TEAM_LEADER,surveyresults.FNAME,surveyresults.LNAME,surveyresults.ID,Avg(surveyresults.RATING) AS RATINGFromsurveyresultsInner Join survey ON surveyresults.ID = survey.IDWheresurvey.INACTIVE Not Like 'YES'Group Bysurveyresults.IDORDER BYRATING 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>";[/code] Link to comment https://forums.phpfreaks.com/topic/12071-coded-table-output/#findComment-45978 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.