I've got my news archives working fine (thanks everyone that's helped).
What I'm finding now is I'm having trouble sorting by popularity.
I have a table for the news items, it has id, news, subject, image, link, popularity as its fields.
I have got the popularity incrimenting by one each time a news item is clicked on, works just fine
On the page that displays the news I ahve a lil menu on the left that lets users view news by date (asc/desc) or by popularity (asc/desc).
OK, the page that has the menu sends its variables like this:
Code: Select all
<a href="/news_archives.php?direction=ASC">Old stories First</a><br>
<a href="/news_archives.php?direction=DESC">New stories First</a><br>
<a href="/news_archives.php?direction=popplus">Most Popular First</a><br>
<a href="/news_archives.php?direction=popminus">Least Polular First</a><br>I got the sort by date one working originally with this method:
Code: Select all
$travel = $_GET['direction'];
// Make sure user hasn't set the direction variable to something other than DESC and ASC
if (($travel == "DESC") || ($travel == "ASC"))
{
mysql_select_db($dbname);
$sql = "SELECT * FROM newscontent ORDER BY id $travel";
$content = mysql_query($sql);
}
else { } // Do nothing because the user has altered the value of directionSo now I want to get the sort by popularity section and my feeble knowlege of PHP led me to try this:
Code: Select all
$travel = $_GET['direction'];
if ($travel = "popplus")
{
$dir = "ASC";
mysql_select_db($dbname);
$sql = "SELECT * FROM newscontent ORDER BY popularity $dir";
$content = mysql_query($sql);
}
else { } // Do nothing because the user has altered the value of direction
if ($travel = "popminus")
{
$dir = "DESC";
mysql_select_db($dbname);
$sql = "SELECT * FROM newscontent ORDER BY popularity $dir";
$content = mysql_query($sql);
}
else { } // Do nothing because the user has altered the value of direction
if ($travel = "ASC")
{
$dir = "ASC";
mysql_select_db($dbname);
$sql = "SELECT * FROM newscontent ORDER BY id $dir";
$content = mysql_query($sql);
}
else { } // Do nothing because the user has altered the value of direction
if ($travel = "DESC")
{
$dir = "DESC";
mysql_select_db($dbname);
$sql = "SELECT * FROM newscontent ORDER BY id $dir";
$content = mysql_query($sql);
}
else { } // Do nothing because the user has altered the value of directionThanks for all your help everyone, what a fantastic community this is.
Rob