Jump to content

Recommended Posts

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

[code]
$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>";
[/code]


Link to comment
https://forums.phpfreaks.com/topic/12071-coded-table-output/
Share on other sites

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

that might have been easier... I went this way:
[code]
$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>";
[/code]
Link to comment
https://forums.phpfreaks.com/topic/12071-coded-table-output/#findComment-45978
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.