Im trying to sort the results of my database. Well it dont work.
<div>
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td class="story_title">Welcome <? print $usrname ?> to the Stories Archive</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td width="79%">Here you can search though our growing library of stories. You can also easily add your own stories to the site just remember to follow the rules.<br />
<br />
The Stories are listed in order of newest to oldest so the latest story will always be right at the top of the list for you to read.<br /><br />
As an added bonus, you can view and add comments about the stories, this is great if you find a problem with a story, or just want to make general comments.
You too can add stories to the story archive to share with everyone.<br /><br />
Enjoy reading through the stories.</td>
<td width="20%" class="pink"><div align="center"><p class="story_subtitle">Share</p></div><div>
<p align="center">Hello <? print $usrname ?> got a great story you want to share with everyone, post it here.<br />
<br />
<a href="stories_upload.php">Click here to upload a story</a></p></div></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td class="pink"><a href="javascript:ajaxpage('infobox/rules.php', 'infobox');">Rules</a> | <a href="javascript:ajaxpage('infobox/copyright.php', 'infobox');">Copyright</a> | <a href="javascript:ajaxpage('infobox/complaints.php', 'infobox');">Complaints</a> | <a href="javascript:ajaxpage('infobox/comments.php?id=6&usrname=<?php print $usrname?>', 'infobox');">Comments <?php
$link = mysql_connect("mysql10.streamline.net", "jennifersp", "s92630");
mysql_select_db("jennifersp", $link);
$id = "6";
$result = mysql_query("SELECT * FROM site_comments WHERE artical_id = $id", $link);
$num_rows = mysql_num_rows($result);
echo "(";
echo "$num_rows";
echo ")";
?></a></td>
</tr>
</table>
<div id="infobox">
</div>
<form name="sort" action="stories.php?sort=<?php echo $_GET['sort'] ?>; method="post" >
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td class="story_title2">Sort by: <select name="sort" id="sort">
<option value="author">Author</option>
<option value="poster">Poster</option>
<option value="ASND">Oldest to newest</option>
<option value="DESC">Newest to oldest</option>
</select> <input type="submit" value="Submit Edit" /></td>
</tr>
</table>
</form>
</div>
<div>
<?php
$id = "sort";
// Database connect //
$server = mysql_connect("mysql10.streamline.net", "jennifersp", "s92630");
$connection = mysql_select_db($server);
//Connect to stories table //
If ($sort == 'DESC'){
$sql = "SELECT s.`id`, s.`title`, s.`author`, s.`poster`, COUNT(c.`story_id`) AS `ct` FROM `storys` s LEFT JOIN `storys_comments` c ON s.`id`= c.`story_id` GROUP BY s.`id` DESC";
Elseif ($sort == 'ASND'){
$sql = "SELECT s.`id`, s.`title`, s.`author`, s.`poster`, COUNT(c.`story_id`) AS `ct` FROM `storys` s LEFT JOIN `storys_comments` c ON s.`id`= c.`story_id` GROUP BY s.`id`";
Elseif ($sort == 'poster'){
$sql = "SELECT s.`id`, s.`title`, s.`author`, s.`poster`, COUNT(c.`story_id`) AS `ct` FROM `storys` s LEFT JOIN `storys_comments` c ON s.`id`= c.`story_id` GROUP BY s.`poster`";
Elseif ($sort == 'author'){
$sql = "SELECT s.`id`, s.`title`, s.`author`, s.`poster`, COUNT(c.`story_id`) AS `ct` FROM `storys` s LEFT JOIN `storys_comments` c ON s.`id`= c.`story_id` GROUP BY s.`author`";
Else {
$sql = "SELECT s.`id`, s.`title`, s.`author`, s.`poster`, COUNT(c.`story_id`) AS `ct` FROM `storys` s LEFT JOIN `storys_comments` c ON s.`id`= c.`story_id` GROUP BY s.`author` DESC";
$result = mysql_query($sql) or die("Query failed($sql): " . mysql_error());
if(mysql_num_rows($result))
{
print '<table width="100%" border="0" cellpadding="4" cellspacing="1" >';
print '<TR class="story_top"><td width="40%">Story</td><td width="10%"></td><td width="20%">Author</td><td width="15%">Poster</td><td width="15%">Comments</td></TR>';
$i = 0;
while($row = mysql_fetch_array($result))
{
if($i++ % 2)
{
print '<tr class="pink">';
}
else
{
print '<tr class="wight">';
}
//the output//
printf(
"<td><a href=\"story_display.php?id=%s&usrname=$usrname\">%s</a>" .
"</td><td><a href=\"javascript:ajaxpage('includes-functions/story_preview.php?id=%s&usrname=$usrname', 'story%s');\">(Preview)</a>" .
"</td><td><span style=\"TEXT-ALIGN:center\">%s</span></td>" .
"<td>%s</td>" .
"<td><a href=\"javascript:ajaxpage('includes-functions/story_comments_preview.php?id=%s&usrname=$usrname', 'story%s');\"><div align=\"center\">%s</div></a>" .
"</tr><tr bgcolor=\"#febef3\"><td colspan=\"5\" id=\"story%s\">" .
"</td></tr>",
$row["id"],
$row["title"],
$row["id"],
$row["id"],
$row["author"],
$row["poster"],
$row["id"],
$row["id"],
$row["ct"],
$row["id"]
);
}
print '</table>';
}
else
{
print '<p class="error">Data error: no records found.</p>';
}
?>
</div>
Error:
Parse error: syntax error, unexpected T_ELSEIF in /home/fhlinux168/d/dev.cossycomforts.com/user/htdocs/includes-blocks/stories.php on line 59