Note that there are some explanatory texts on larger screens.

plurals
  1. POMost efficient way to sort a leaderboard in SQL and update it in a table using PHP
    text
    copied!<p>I might not have worded this right, but basically here is what I want to do:</p> <ul> <li>Display the leaderboard in a HTML table</li> <li>Each heading in the leaderboard is a link (e.g. score, time, kills)</li> <li>When each link is click it sorts the table depending what link is click (e.g. if kills is clicked it sorts the data showing the move kills at the top)</li> </ul> <p><a href="http://stuartjones.me/Staroids/leaderboard.php" rel="nofollow">Here</a> is a link to my current leaderboard which works fine.</p> <p>This is the code I have to far:</p> <pre><code>&lt;div id="board"&gt; &lt;table border="1" cellspacing="0" cellpadding="2" width="620"&gt;&lt;tbody&gt; &lt;thead&gt; &lt;tr&gt; &lt;td&gt;Name&lt;/td&gt; &lt;td&gt;Score&lt;/td&gt; &lt;---- WHEN CLICK = SORT IT BY SCORE &lt;td&gt;Wave Reached&lt;/td&gt; &lt;---- WHEN CLICK = SORT IT BY WAVE &lt;td&gt;Seconds Survived&lt;/td&gt; &lt;---- WHEN CLICK = SORT IT BY SECONDS &lt;td&gt;Kills&lt;/td&gt; &lt;---- WHEN CLICK = SORT IT BY KILLS &lt;td&gt;Deaths&lt;/td&gt; &lt;---- WHEN CLICK = SORT IT BY DEATHS &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;?php $connect = mysql_connect("localhost","localhost", "password"); if (!$connect) { die(mysql_error()); } mysql_select_db("staroids"); $results = mysql_query("SELECT name, score, wave, seconds, kills, deaths FROM scores ORDER BY score DESC LIMIT 10"); while($row = mysql_fetch_array($results)) { $name = $row['name']; $score = $row['score']; $wave = $row['wave']; $seconds = $row['seconds']; $kills = $row['kills']; $deaths = $row['deaths']; ?&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo $name;?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $score;?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $wave;?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $seconds;?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $kills;?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $deaths;?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php } mysql_close($connect); ?&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; </code></pre> <p>I hope this explains what I intend to do.</p> <p>The code above displays the scores in descending order. Is there away to run a PHP script when a link is pressed in HTML like with JavaScript so it runs a specific query?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload