0

i have a table being echo'd from a single query to a table in our database and i get it to echo out the following table;

http://www.skulldogs.com/dev/testview.php

i want it to sort the "yellow" rows under the correct green rows where the "mainToon" name matches for example:

high voltege

--REAL MCCOY

--Cpt Hook

riazall

-- Valeside

my code to echo the above page is;

<?php

  $result = mysql_query("SELECT * FROM `members`");
  echo "<table border='1'>
  <tr>
  <th>Character ID</th>
  <th>Name</th>
  <th>MainToon</th>
  <th>toonCategory</th>
  </tr>";
    while ($row = mysql_fetch_array($result)) {
        $characterID = $row['characterID'];
        $name = $row['name'];
        $startDateTime = $row['startDateTime'];
        $logonDateTime = $row['logonDateTime'];
        $logoffDateTime = $row['logoffDateTime'];
        $location = $row['location'];
        $role = $row['role'];
        $vouchedBy = $row['vouchedBy'];
        $positionHeld = $row['positionHeld'];
        $remarks = $row['remarks'];
        $afkNotice = $row['afkNotice'];
        $toonCategory = $row['toonCategory'];
        $mainToon = $row['mainToon'];
        $watch = $row['watch'];

    if ($toonCategory == 'Main Toon') {
        echo "<tr bgcolor='#00FF00'>"; }
    else {
        echo "<tr bgcolor='#FFFF00'>"; }
    echo "<td>" . $characterID . "</td>";
    echo "<td>" . $name . "</td>";
    echo "<td>" . $mainToon . "</td>";
    echo "<td>" . $toonCategory . "</td>";
    echo "</tr>";
  }
    echo "</table>";

?>

at the moment i am not echo the other data until i can figure out how to display this table accordingly. can it be done this way?

this is how i want to display the table;

http://www.skulldogs.com/dev/mockup.php

2 Answers 2

4

Add an ORDER BY clause to your sql:

SELECT * FROM `members` ORDER BY toonCategory;

If there are other values above and below "Main Toon", You can order by a boolean:

SELECT * FROM `members` ORDER BY toonCategory = 'Main Toon' DESC;

EDIT:

Now I see what you are after as you have put up the example, try:

SELECT * FROM `members` ORDER BY CONCAT(MainToon, Name);

if the blank spaces are empty strings or:

SELECT * FROM `members` ORDER BY COALESCE(MainToon, Name) DESC, Name;

if the blank rows are null.

Sign up to request clarification or add additional context in comments.

2 Comments

it only orders them in the table view by "category" not links the toon with its "ALT" (second toon!) which can be found in the "mainToon" echo.
@StephenJackson I've 2 possible new answers - hopefully one will work for you.
1

Try SELECT * FROM members ORDER BY toonCategory;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.