fostersguy Posted August 29, 2011 Share Posted August 29, 2011 Hi there, just registered and in need of help, this looks a good place to start! I'm a php beginner so please bear with me I have a mysql database which holds 3 pieces of info id: match: 1: I'm trying to sort the results using ORDER BY match ASC but for some reason it's just not for having it... Can't work out if it's an error with my php code or my table. I can order by "ID" no problem but I when I try ordering alphabetically by "match" it won't. my code is: mysql_connect("***.***.***") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); $query = "SELECT * FROM employees WHERE flag = 'tv' ORDER BY match ASC"; $result = mysql_query($query) or die ("Query failed"); $numrows = (mysql_num_rows ($result)); // loop to create rows if($numrows >0){ echo "<table width = 100% border = '0' cellspacing = '2' cellpadding = '0' >"; // loop to create columns $position = 1; while ($row = mysql_fetch_array($result)){ if($position == 1){echo "<tr>";} echo " <td align = 'center'><a href=\"http://www.website.eu/sport-stream/1/{$row['id']}.html\" target=_blank>{$row['match']} <br> <img src=\"{$row['8']}\" width=\"100\" height=\"70\" /> </a> </td> "; if($position == 4){echo "</tr> "; $position = 1;}else{ $position++;} }//while $end = ""; if($position != 1){ for($z=(4-$position); $z>0 ; $z--){ $end .= "<td></td>"; } $end .= "</tr>"; } echo $end."</table> "; }//if And here's a cap of my database: any help for a php n00b would be greatly appreciated! Link to comment https://forums.phpfreaks.com/topic/245955-order-by-help/ Share on other sites More sharing options...
AyKay47 Posted August 29, 2011 Share Posted August 29, 2011 "match" is a mysql reserved word.. in oreder to properly use this field name.. encase it in backticks.. $query = "SELECT * FROM employees WHERE flag = 'tv' ORDER BY `match` ASC"; Link to comment https://forums.phpfreaks.com/topic/245955-order-by-help/#findComment-1263164 Share on other sites More sharing options...
amg182 Posted August 29, 2011 Share Posted August 29, 2011 Match field may be a problem as it's stored as Blob, not sure if you can order by blob. Perhaps change to varchar or int Link to comment https://forums.phpfreaks.com/topic/245955-order-by-help/#findComment-1263168 Share on other sites More sharing options...
fostersguy Posted August 29, 2011 Author Share Posted August 29, 2011 haha oh wow thankyou so much, I will do a bit of research on here to find out exactly the in's and out's of what you told me. Prefer to understand what something means in php thanks again Link to comment https://forums.phpfreaks.com/topic/245955-order-by-help/#findComment-1263169 Share on other sites More sharing options...
fostersguy Posted August 29, 2011 Author Share Posted August 29, 2011 Match field may be a problem as it's stored as Blob, not sure if you can order by blob. Perhaps change to varchar or int Aykay's suggestion worked a treat, but would I still be wise to change the field to what you suggested? Link to comment https://forums.phpfreaks.com/topic/245955-order-by-help/#findComment-1263170 Share on other sites More sharing options...
AyKay47 Posted August 29, 2011 Share Posted August 29, 2011 depends what data you are storing as a blob..? Link to comment https://forums.phpfreaks.com/topic/245955-order-by-help/#findComment-1263178 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.