So i made a simple forum that selects the data in the database and orders them by their date published DESC.
Heres the only problem...so i have a row called TYPE in the forum_question Table. How do i select the ones with the TYPE set to STICKY and display them FIRST and then display the rest of the data after that... 🙁
heres the code i have so far
<?php
function learnCategory($category){
include("../housekeeping/dbconnect.php");
$username=$_SESSION["myusername"];
//This selects the Forum from the database
$sql ="SELECT * FROM `SocInt`.`forum_question` WHERE `category`='$category' ORDER BY date DESC";
$result=mysql_query($sql);
$count=1;
$today=date('F j, Y h:i');
echo "<center><b>Current Time</b>:: $today</center>";
echo "<table width=\"525\" id=\"emailInbox\" bgcolor=\"#000000\" style=\"color:#FFFFFF\">";
echo "<tr id=\"emailInbox\">";
echo "<td id=\"emailInbox\" width=\"300px;\">Topic</td>";
echo "<td id=\"emailInbox\" width=\"50px;\">Views</td>";
echo "<td id=\"emailInbox\" width=\"50px;\">Reply</td>";
echo "<td id=\"emailInbox\" width=\"125px;\">Author</td>";
echo "</tr>";
echo "</table>";
while($row = mysql_fetch_array($result)){
$id=$row['id'];
$topic=$row['topic'];
$category=$row['category'];
$message=$row['message'];
$date=$row['date'];
$views=$row['views'];
$replies=$row['replies'];
$author=$row['author'];
$type=$row['type'];
//if type is sticky then it changes its background color to brownish.
if($type=='sticky'){
echo "<table width=\"525\" id=\"emailInbox\" bgcolor=\"#D8C9AB\" >";
echo "<tr id=\"emailInbox\" bgcolor=\"#D8C9AB\">";
echo "<td id=\"emailInbox\" width=\"300px;\" bgcolor=\"#D8C9AB\"><a href=\"view_topic.php?id=$id\">$topic</a></td>";
echo "<td id=\"emailInbox\" width=\"50px;\" bgcolor=\"#D8C9AB\">$views</td>";
echo "<td id=\"emailInbox\" width=\"50px;\" bgcolor=\"#D8C9AB\">$replies</td>";
echo "<td id=\"emailInbox\" width=\"125px;\" bgcolor=\"#D8C9AB\">$author</td>";
echo "</tr>";
echo "</table>";
}else{echo "<table width=\"525\" id=\"emailInbox\" >";
echo "<tr id=\"emailInbox\">";
echo "<td id=\"emailInbox\" width=\"300px;\"><a href=\"view_topic.php?id=$id\">$topic</a></td>";
echo "<td id=\"emailInbox\" width=\"50px;\">$views</td>";
echo "<td id=\"emailInbox\" width=\"50px;\">$replies</td>";
echo "<td id=\"emailInbox\" width=\"125px;\">$author</td>";
echo "</tr>";
echo "</table>";
}
};
echo "<table width=\"525\" id=\"emailInbox\" bgcolor=\"#CCCCCC\" style=\"color:#FFFFFF\">";
echo "<tr id=\"emailInbox\">";
echo "<td id=\"emailInbox\" width=\"300px;\"><a href=\"new_topic.php?category=$category\">New Topic</a></td>";
echo "</tr>";
echo "</table>";
}
?>