jomagi Posted February 17, 2009 Share Posted February 17, 2009 Hi there! I'm using MySQL 5.0.67, and I'm bilding a website with php. I want to order the data by initial letter of the content, but not ascending or descending but order by letter J, then C, then W, then O and the others letters dont matter because just have with this initial letters. It's for displaying the data by styles in the php page, with the jazz style in top. Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/145578-solved-question-of-ordering/ Share on other sites More sharing options...
Mchl Posted February 17, 2009 Share Posted February 17, 2009 http://imthi.com/blog/programming/mysql-order-by-field-custom-field-sorting.php Quote Link to comment https://forums.phpfreaks.com/topic/145578-solved-question-of-ordering/#findComment-764279 Share on other sites More sharing options...
fenway Posted February 17, 2009 Share Posted February 17, 2009 Just not that that code does NOT deal with the situation where there are other values in your list other than the ones your explicit "rank" -- careful. Quote Link to comment https://forums.phpfreaks.com/topic/145578-solved-question-of-ordering/#findComment-764287 Share on other sites More sharing options...
Mchl Posted February 17, 2009 Share Posted February 17, 2009 I suppose that FIELD() will return 0 for those, so they'll be grouped at the top in order of primary key. Quote Link to comment https://forums.phpfreaks.com/topic/145578-solved-question-of-ordering/#findComment-764289 Share on other sites More sharing options...
jomagi Posted February 17, 2009 Author Share Posted February 17, 2009 Hi try but dont work and for what I understand this is for ordering by field name and what I need is ordering the records with base in the field "estilo" and that appear on top the "Jazz" records Letter "J", next the records beggining letter "C", next beggining letter "W" and for last letter "O". Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/145578-solved-question-of-ordering/#findComment-764340 Share on other sites More sharing options...
Mchl Posted February 17, 2009 Share Posted February 17, 2009 Try: SELECT * FROM table ORDER BY FIELD(SUBSTRING(estilo,1,1),"J","C","W","O") Quote Link to comment https://forums.phpfreaks.com/topic/145578-solved-question-of-ordering/#findComment-764358 Share on other sites More sharing options...
fenway Posted February 17, 2009 Share Posted February 17, 2009 I suppose that FIELD() will return 0 for those, so they'll be grouped at the top in order of primary key. Yup... so you have to order using an "inverted" FIELD().... Quote Link to comment https://forums.phpfreaks.com/topic/145578-solved-question-of-ordering/#findComment-764368 Share on other sites More sharing options...
jomagi Posted February 17, 2009 Author Share Posted February 17, 2009 Dont work!!! mysql_select_db($database_dargil_site, $dargil_site); $query_listdestaques = "SELECT * FROM destaques ORDER BY FIELD(SUBSTRING(estilo,1,1),"J","C","W","O")"; $listdestaques = mysql_query($query_listdestaques, $dargil_site) or die(mysql_error()); $row_listdestaques = mysql_fetch_assoc($listdestaques); $totalRows_listdestaques = mysql_num_rows($listdestaques); ?> This is the code I have in this moment! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/145578-solved-question-of-ordering/#findComment-764401 Share on other sites More sharing options...
Mchl Posted February 17, 2009 Share Posted February 17, 2009 Of course it doesn't. You're using double quotes in double quoted string. Either escape them, or enclose the string in single quotes. (Or change internal quotes to single quotes) $query_listdestaques = "SELECT * FROM destaques ORDER BY FIELD(SUBSTRING(estilo,1,1),"J","C","W","O")"; Quote Link to comment https://forums.phpfreaks.com/topic/145578-solved-question-of-ordering/#findComment-764405 Share on other sites More sharing options...
jomagi Posted February 17, 2009 Author Share Posted February 17, 2009 That resolve the problem! Thankyou very much and keep the good work! Quote Link to comment https://forums.phpfreaks.com/topic/145578-solved-question-of-ordering/#findComment-764427 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.