Jump to content

Need help sorting table output results


affluent980

Recommended Posts

I have a table that tracks collects lead information like name email and phone number.  it starts with the LeadID, which is primary.  When the results are displayed, they are in a wierd order that i don't understand.  I would like it to sort the displayed results by the LeadID, so they are in order.  Please help!  Here is the code as is:

 

<?php

echo "<table border='1'>
<tr>
<th>LeadID</th>
<th>CID</th>
<th>Category</th>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Date</th>
<th>Time</th>
<th>Keyword</th>
<th>Good Lead</th>
<th>Bad Lead</th>
<th>Closed</th>
<th>Revenue</th>
</tr>";

$result = mysql_query("SELECT * FROM Leads WHERE CID='$session->username'"); 

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['LeadID'] . "</td>";
  echo "<td>" . $row['CID'] . "</td>";
  echo "<td>" . $row['Category'] . "</td>";
  echo "<td>" . $row['Name'] . "</td>";
  echo "<td>" . $row['Email'] . "</td>";
  echo "<td>" . $row['Phone'] . "</td>";
  echo "<td>" . $row['Date'] . "</td>";
  echo "<td>" . $row['Time'] . "</td>";
  echo "<td>" . $row['Keyword'] . "</td>";
  echo "<td>" . $row['More'] . "</td>";
  echo "<td>" . $row['Less'] . "</td>";
  echo "<td>" . $row['Closed'] . "</td>";
  echo "<td>" . $row['Revenue'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

}

/* Link back to main */
echo "<br>Back To [<a href=\"main.php\">Main</a>]<br>";

?>

Link to comment
https://forums.phpfreaks.com/topic/142989-need-help-sorting-table-output-results/
Share on other sites

// order by lowest to highest

$result = mysql_query ( "SELECT * FROM Leads WHERE CID='" . $session->username . "' ORDER BY LeadID;" );

// order by highest to lowest

$result = mysql_query ( "SELECT * FROM Leads WHERE CID='" . $session->username . "' ORDER BY LeadID DESC;" );

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.