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

CabCon

Head Administrator
Staff member
Head Staff Team
Messages
5,093
Reaction score
2,881
Points
1,103
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
5,093
Reaction score
2,881
Points
1,103
I had to do something similar for a game i was working on awhile ago, take a look at
Please, Log in or Register to view URLs content!

If you still need some help PM me :tonguewink:
Thank you, and yeah I already took a look at arrays to organize it. But I found this Plugin
Please, Log in or Register to view URLs content!
and it works great. :smile:
 

Kyle Fardy

Veteran
Donator
Messages
179
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
86
Points
793
I actually created a sorting function using PHP for one of my uni projects here:
Please, Log in or Register to view URLs content!


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
5,093
Reaction score
2,881
Points
1,103
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:
Please, Log in or Register to view URLs content!


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

Veteran
Donator
Messages
179
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