MySQL Enum field not ordering correctly

Thats because: It will order in the order the enum values are defined at table level – not the actual varchar/int/etc value.

Fix:

SELECT CAST(a.enumfield AS CHAR(255)) AS enumfield, a.*
FROM `mytable` a
ORDER BY CAST(a.enumfield AS CHAR(255)) ASC

Tip: change it to CAST X as INT – if you’ve got integers, so on and so forth.

Tip2: use table aliases

PHP: Always redirect to the non-www and https version of the current page

<?php
if(empty($_SERVER[‘HTTPS’]) || $_SERVER[‘HTTPS’] == “off”){ //check for non secure connections
$redirect = ‘https://’ . str_replace(‘www.’, ”, $_SERVER[‘HTTP_HOST’]) . $_SERVER[‘REQUEST_URI’];
header(‘HTTP/1.1 301 Moved Permanently’); //make a permanent redirect
header(‘Location: ‘ . $redirect);
exit();
}elseif(substr($_SERVER[‘HTTP_HOST’], 0, 4) === ‘www.’){ //check if the requested url begins with “www.”
$redirect = ‘https://’ . str_replace(‘www.’, ”, $_SERVER[‘HTTP_HOST’]) . $_SERVER[‘REQUEST_URI’];
header(‘HTTP/1.1 301 Moved Permanently’);¬† //make a permanent redirect
header(‘Location: ‘ . $redirect);
exit();
}