Article is focused on way how to alter existing code for showing submited post as a table. But scores are ordered in descending way and first 3 higest scores are differently styled. Latest part of article list number of ways hot to improve our aplication.
Numbering posted results in a chart
Before our update to code, we displayed in first table row ID number. For proper ordering from top score to bottom we must order query in descent way by score ID. Then we create auxiliary variable $postiton.
$position = 1; // first initialization of position
while($row = mysqli_fetch_array($output)){
… output omited
//echo „<td>“ . $row[‚id‘] . „</td>“; this line is changed to incrementing number showing position of the score in chart
echo „<td id=\“$display\“>“ . $position++ . „</td>“; // increases number of position after disply by one
$position variable is increased by 1 after all pass trough while loop.
Different colors for first positions
A bit harder update must be done for marking of first three score position for further stylling into a diferent colors.
In our code we introduced new variable $display. Into $display variable is assigned name for <td> id first, secondandthree and others. In switch statement along value of $position variable these values are added into a $display variable.
Next part show how this update is implemented in final php code:
$position = 1; // first initialization of position
while($row = mysqli_fetch_array($output)){ //next rows outputed in while loop
//echo “ <div class=\“mailinglist\“> “ ; class identification must differ first, two second and other position
switch ($position) { // along position from first to bottom displayed rows are marked with different names and recolored in style.css
case 1: $display=’first‘ ; break;
case 2:
case 3: $display=’secondandthree‘ ; break;
default: $display=’others‘ ;
};
echo „<tr>“;
//echo „<td>“ . $row[‚id‘] . „</td>“; this line is changed to incrementing number showing position of the score in chart
echo „<td id=\“$display\“>“ . $position++ . „</td>“; // increases number of position after disply by one
We inform you that we use cookies and other technologies on this site to function and improve the operation of the site, ensure it, provide social networking features, personalize content and ads to users, and analyze traffic and user behavior. For more information, please read our Terms of Use and Cookies. You can prevent cookies from being processed by changing the settings in your Internet browser.OkPrivacy policy