Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP / mySQL ORDER BY issue
    text
    copied!<p><a href="http://www.badnutbeats.co.uk/inotherwords/browse.php?alphabet=s&amp;subject=art&amp;listtype=popular" rel="nofollow">Click the "strip'slashes'" link to see the page I'm referring to</a></p> <p>As you can see, I have this voting system setup for different definitions of phrases. In the database the votes are dealt with in a table of their own, but are linked to the 'phrases' table via IDs. I want to order the phrases by the balance of votes, but as the votes aren't part of the table I'm selecting in my SQL query, I'm not sure how to do it.</p> <p>I'm able to create the balance of votes, which can be seen beneath each phrase definition, but I can't work out how to ORDER BY them. I thought about creating the 'balance' and then updating it into the database when a new vote is registered, but as the insertion of votes is into the 'vote' table, I can't recall it when recalling the phrases.</p> <p>Can somebody point me in the right direction please!</p> <p>Code:</p> <pre><code>$query="select id, date, original, inotherwords, author from phrases where original='".$head."'"; $result=mysql_query($query); $thenumber = 1; echo '&lt;h2&gt;Original Phrase&lt;/h2&gt;'; echo '&lt;p&gt;'.stripslashes($head).'&lt;/p&gt;&lt;br&gt;'; echo '&lt;h2&gt;In Other Words&lt;/h2&gt;'; while($row = mysql_fetch_array($result)){ $pv = $pulse-&gt;countUpVotes($row['id']); $nv = $pulse-&gt;countDownVotes($row['id']); $balance = ($pv - $nv); echo '&lt;p&gt;'.$thenumber.'. '.stripslashes(nl2br($row['inotherwords'])).' - '; echo $pulse-&gt;voteHTML($row['id']); echo '&lt;/p&gt;'; echo '&lt;p&gt;&lt;b&gt;Author&lt;/b&gt; - '.stripslashes($row['author']).' - submitted on '.$row['date'].'&lt;/p&gt;'; echo 'Balance - '.$balance.'&lt;br&gt;&lt;br&gt;'; $thenumber++; } </code></pre>
 

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