PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am wrinting a script to sort mysql entries. I have the correct table displayed but it seems its running my If statements without checking the variable. Im trying to get the table to be sorted based on user input
if($sort == title); {
$query = "SELECT jcode, designation, responsibilities, city, posted FROM listing ORDER BY designation";
}
if($sort == city);
{
$query = "SELECT jcode, designation, responsibilities, city, posted FROM listing ORDER BY city";
}
if($sort == 'title'){
$query = "SELECT jcode, designation, responsibilities, city, posted FROM listing ORDER BY designation";
}
if($sort == 'city'){
$query = "SELECT jcode, designation, responsibilities, city, posted FROM listing ORDER BY city";
}
You should probably have if ... elseif statements instead of multiple if statements. You need to put your strings into quotes (turn up your error reporting to see the notices being generated).
You really should also start coding for reg_globals off as it is deprecated and could be excluded from the next major version of PHP.
if($sort == title); {
$query = "SELECT jcode, designation, responsibilities, city, posted FROM listing ORDER BY designation";
}
if($sort == city);
{
$query = "SELECT jcode, designation, responsibilities, city, posted FROM listing ORDER BY city";
}