redfox
11-26-2010, 04:57 PM
Sorry for making another thread, but I am also having problems with some if else statements. Maybe you can take a gander and tell me if you see anything wrong:
<?php
/* See if variables are in URL, substitute if not */
if (count($_GET["sortby"])<= 0)
$sortby = "last";
else
$sortby = $_GET['sortby'];
if (count($_GET["order"])<= 0)
$order = "ASC";
else
$order = "DESC";
/* Apply sorting before display */
mysql_select_db($database_ballot, $ballot);
$query="SELECT * FROM votes ORDER BY $sortby $order";
$query2="SELECT * FROM votes";
$result=mysql_query($query);
$result2=mysql_query($query2);
$num=mysql_numrows($result2);
/* Apply order to link that is displayed */
if ($order=="ASC")
{
echo('<a href="index.php?sortby=first&order=DESC"><strong>
First Name:</strong></a>');
}
elseif ($order=="DESC")
{
echo('<a href="index.php?sortby=first&order=ASC"><strong>First Name:</strong></a>');
}
else
{
echo('error');
}
/* More links follow below, not repeated for the sake of space */
?>
So essentially, I have a page that displays MySQL results in a table. They display in a certain order according to the variables in the URL. It displays them just fine when there are variables in the URL, however it will not apply a value to it when it's just the index.php. So Problem #1, I cannot get it to display by default the last name ascending. Problem #2, for the links I can go to the index without variables, click on the link, with it being DESC, while the URL var is DESC it will be the ASC link, I click it again and the link is ASC from then out while the URL var is ASC.
Thanks again
<?php
/* See if variables are in URL, substitute if not */
if (count($_GET["sortby"])<= 0)
$sortby = "last";
else
$sortby = $_GET['sortby'];
if (count($_GET["order"])<= 0)
$order = "ASC";
else
$order = "DESC";
/* Apply sorting before display */
mysql_select_db($database_ballot, $ballot);
$query="SELECT * FROM votes ORDER BY $sortby $order";
$query2="SELECT * FROM votes";
$result=mysql_query($query);
$result2=mysql_query($query2);
$num=mysql_numrows($result2);
/* Apply order to link that is displayed */
if ($order=="ASC")
{
echo('<a href="index.php?sortby=first&order=DESC"><strong>
First Name:</strong></a>');
}
elseif ($order=="DESC")
{
echo('<a href="index.php?sortby=first&order=ASC"><strong>First Name:</strong></a>');
}
else
{
echo('error');
}
/* More links follow below, not repeated for the sake of space */
?>
So essentially, I have a page that displays MySQL results in a table. They display in a certain order according to the variables in the URL. It displays them just fine when there are variables in the URL, however it will not apply a value to it when it's just the index.php. So Problem #1, I cannot get it to display by default the last name ascending. Problem #2, for the links I can go to the index without variables, click on the link, with it being DESC, while the URL var is DESC it will be the ASC link, I click it again and the link is ASC from then out while the URL var is ASC.
Thanks again