yami007 Posted December 28, 2008 Share Posted December 28, 2008 how can i display the contents ordered by alphabets? well, i want to get the results this way: <div>A</div> <div>akon...</div> <div>amine...</div> <div>amel...</div> <div>B</div> <div>bryan...</div> <div>britanie...</div> so on..... please help Quote Link to comment https://forums.phpfreaks.com/topic/138639-solved-mysql-query-select-order-by-alpabets/ Share on other sites More sharing options...
MadTechie Posted December 28, 2008 Share Posted December 28, 2008 Append "ORDER BY field name ASC" to the SQL statment Quote Link to comment https://forums.phpfreaks.com/topic/138639-solved-mysql-query-select-order-by-alpabets/#findComment-724867 Share on other sites More sharing options...
yami007 Posted December 28, 2008 Author Share Posted December 28, 2008 well, i'm already doing what u said; order by name, but what i want to do is like in this page http://myplay.com/artists. i hope u help me with it Quote Link to comment https://forums.phpfreaks.com/topic/138639-solved-mysql-query-select-order-by-alpabets/#findComment-724870 Share on other sites More sharing options...
MadTechie Posted December 28, 2008 Share Posted December 28, 2008 Okay and whats the problem ? its basically a while loop check first char is its diffrent then echo the new one quick draft untested example $letter = ""; while($row = mysql_fetch_array($result)) { $fletter = substr($row['0'],0, 1); if($letter != $fletter) { $letter = $fletter; echo "$letter<br>"; } echo $row['0']."<br>"; } the rest is basically CSS/HTML Quote Link to comment https://forums.phpfreaks.com/topic/138639-solved-mysql-query-select-order-by-alpabets/#findComment-724872 Share on other sites More sharing options...
yami007 Posted December 29, 2008 Author Share Posted December 29, 2008 i dont think i get your code, i tried it though and it gave me : 5 4 5 6 5 6 5 what's that supposed to mean?? Quote Link to comment https://forums.phpfreaks.com/topic/138639-solved-mysql-query-select-order-by-alpabets/#findComment-725053 Share on other sites More sharing options...
Mark Baker Posted December 29, 2008 Share Posted December 29, 2008 So if row[0] isn't the content retrieved from your database, pick the column that is Quote Link to comment https://forums.phpfreaks.com/topic/138639-solved-mysql-query-select-order-by-alpabets/#findComment-725054 Share on other sites More sharing options...
yami007 Posted December 29, 2008 Author Share Posted December 29, 2008 sorry madtechie, i think i was sleepy so i ddn concetrate on it, thanks to you and mark baker for waking me up Quote Link to comment https://forums.phpfreaks.com/topic/138639-solved-mysql-query-select-order-by-alpabets/#findComment-725069 Share on other sites More sharing options...
yami007 Posted December 29, 2008 Author Share Posted December 29, 2008 ok guys that's how i turned this code into : <?php $query ="SELECT * FROM singers ORDER BY name"; $singers_set = mysql_query($query); while ($singers = mysql_fetch_array($singers_set)) { $fletter = substr($singers['name'],0, 1); if ($letter != $fletter) { $letter = $fletter; echo "$letter<br>"; } echo $singers['name']."<br>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/138639-solved-mysql-query-select-order-by-alpabets/#findComment-725072 Share on other sites More sharing options...
MadTechie Posted December 29, 2008 Share Posted December 29, 2008 Sorry for late reply Mark Baker is correct if you used "SELECT name FROM singers ORDER BY name" the code should of worked i didn't know the field names being used and i don't really test the code i just enter it directly.. anywho glade you got it sorted Quote Link to comment https://forums.phpfreaks.com/topic/138639-solved-mysql-query-select-order-by-alpabets/#findComment-725076 Share on other sites More sharing options...
yami007 Posted December 29, 2008 Author Share Posted December 29, 2008 thanks so much Quote Link to comment https://forums.phpfreaks.com/topic/138639-solved-mysql-query-select-order-by-alpabets/#findComment-725318 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.