Answered How can I sort Items in a database created chart in PHP?

CabCon

Head Administrator
Staff member
Head Staff Team
Messages
4,935
Reaction score
2,896
Points
1,053
Hello,
I need agian your help :grinning:. I have created a database which contains people from a run with the ammount of rounds which they ran. After that I created this script (with some google work :wink:) which create a html chart.

The script:
PHP:
<?php
                    $db = new PDO("mysql:host=HIDDEN;dbname=HIDDEN", 'HIDDEN', 'HIDDEN') or die ("Verbindung nicht möglich");
                    $query_temp = $db->prepare("SELECT * FROM runners");
                    $query_temp->bindParam(':id', $id);
                    $id = 1;
                    $query_temp->execute();
                    echo '<table class="table table-hover">';
                        echo '<tr>';
                            echo '<th>ID</th>';
                            echo '<th>Name</th>';
                            echo '<th>Runden</th>';
                        echo '</tr>';
                        while($id_table = $query_temp->fetch(PDO::FETCH_ASSOC)) {
                            echo '<tr>';
                                echo '<td>'.$id_table['runner_id'].'</td>';
                                echo '<td>'.$id_table['runner_name'].'</td>';
                                echo '<td>'.$id_table['runner_rounds'].'</td>';
                            echo '</tr>';
                        }
                    echo '</table>';
                ?>

The Database:
img


Screenshot how it looks:
img



Now I want to give the users the ability to sort the people for their ammoun of rounds which they ran. Like the most person is at the first place. How can I do this?


Regards,
CabCon.
 

CabCon

Head Administrator
Staff member
Head Staff Team
Messages
4,935
Reaction score
2,896
Points
1,053

Kyle Fardy

Trial Moderator
Staff member
Trial Moderator
Donator
Messages
181
Reaction score
89
Points
888
PHP:
<?php
        $db = new PDO("mysql:host=HIDDEN;dbname=HIDDEN", 'HIDDEN', 'HIDDEN') or die ("Verbindung nicht möglich");
        $query_temp = $db->prepare("SELECT * FROM `runners` ORDER BY `runner_rounds` DESC");
        $query_temp->bindParam(':id', $id);
        $id = 1;
        $query_temp->execute();
            echo '<table class="table table-hover">';
                echo '<tr>';
                    echo '<th>ID</th>';
                    echo '<th>Name</th>';
                    echo '<th>Runden</th>';
                echo '</tr>';
            while($id_table = $query_temp->fetch(PDO::FETCH_ASSOC)) 
            {
                echo '<tr>';
                    echo '<td>'.$id_table['runner_id'].'</td>';
                    echo '<td>'.$id_table['runner_name'].'</td>';
                    echo '<td>'.$id_table['runner_rounds'].'</td>';
                echo '</tr>';
            }
            echo '</table>';
?>

Give That A Try, Let Me Know If It Works
 

vRice

Veteran
Messages
58
Reaction score
89
Points
793
I actually created a sorting function using PHP for one of my uni projects here:
You do not have permission to view link Log in or register now.


When I'm home I will see if I can give you a hand :smile:

EDIT - Nevermind it's been marked answered haha
 

CabCon

Head Administrator
Staff member
Head Staff Team
Messages
4,935
Reaction score
2,896
Points
1,053
PHP:
<?php
        $db = new PDO("mysql:host=HIDDEN;dbname=HIDDEN", 'HIDDEN', 'HIDDEN') or die ("Verbindung nicht möglich");
        $query_temp = $db->prepare("SELECT * FROM `runners` ORDER BY `runner_rounds` DESC");
        $query_temp->bindParam(':id', $id);
        $id = 1;
        $query_temp->execute();
            echo '<table class="table table-hover">';
                echo '<tr>';
                    echo '<th>ID</th>';
                    echo '<th>Name</th>';
                    echo '<th>Runden</th>';
                echo '</tr>';
            while($id_table = $query_temp->fetch(PDO::FETCH_ASSOC))
            {
                echo '<tr>';
                    echo '<td>'.$id_table['runner_id'].'</td>';
                    echo '<td>'.$id_table['runner_name'].'</td>';
                    echo '<td>'.$id_table['runner_rounds'].'</td>';
                echo '</tr>';
            }
            echo '</table>';
?>

Give That A Try, Let Me Know If It Works
I actually created a sorting function using PHP for one of my uni projects here:
You do not have permission to view link Log in or register now.


When I'm home I will see if I can give you a hand :smile:

EDIT - Nevermind it's been marked answered haha
Thanks for helping guys but I already get it working with a jQuery plugin. :y: If you are interested in it, I can take a look for it again.
 

Kyle Fardy

Trial Moderator
Staff member
Trial Moderator
Donator
Messages
181
Reaction score
89
Points
888
Thanks for helping guys but I already get it working with a jQuery plugin. :y: If you are interested in it, I can take a look for it again.
no problem mate im more than happy to help out
 
Last edited by a moderator:
Top