Hi there,
I'm having issue with MySQL's "ORDER BY" clause. I have a database of game information. There are approximately 1000 entries. I am displaying all the results in a list, in alphabetical order. I'm currently only displaying the games that don't start with a number.
My code is below:
$games = mysql_query("select * from games order by game_name asc");
while($gameresult = @mysql_fetch_array($games)) {
$gameresult['game_name'] = trim($gameresult['game_name']);
$gameresult['game_description'] = trim($gameresult['game_description']);
$gameresult['game_path'] = trim($gameresult['game_path']);
$gameresult['game_description'] = str_replace('\"', "", $gameresult[game_description]);
$gn = $gameresult[game_name]{0};
$gameresult[id] = "game".$gameresult[id].".html";
if(!is_numeric($gn)) {
echo "<b><a href='$root$gameresult[id]'>$gameresult[game_name]<span>$gameresult[game_description]</span></a></b>
<br>
$gameresult[game_plays] plays
<br><hr width='50%'>";
}
}
Now this works fine, but in my admin panel when I add a game to the database, irrespective of what letter the game name starts with, it lists it last on the last. Even if I add a game with a name such as "Another Game", it will display it after the "Z"s. Here is the code that adds the entry in the admin panel:
$game_name = $_REQUEST['game_name'];
$game_description = $_REQUEST['game_description'];
$game_path = "games/".$_FILES['game_file']['name'];
$target_path = "../games/";
$target_path = $target_path . basename($_FILES['game_file']['name']);
if(move_uploaded_file($_FILES['game_file']['tmp_name'], $target_path)) {
mysql_query("insert into games(game_name, game_description, game_path, game_plays) values('$game_name', '$game_description', '$game_path', '0')") or die(mysql_error());
echo "<b>The game ($game_name) has been successfully added.</b>";
}
Any idea what the problem is? Any help would be greatly appriciated. Thank you.
Regards,
Mike