ecopetition Posted July 22, 2008 Share Posted July 22, 2008 Hello, I'm trying to find a way to alphabetically order an output. I'm kind of new to PHP so this might be blindingly obvious but I just don't know what to do. Feel free to probe me for info regarding the script and its context. Peter Quote Link to comment https://forums.phpfreaks.com/topic/116082-ordering-an-output/ Share on other sites More sharing options...
wildteen88 Posted July 22, 2008 Share Posted July 22, 2008 Where is the output coming from? How is the output stored within an array? if its an array PHP has many functions for sorting array items, such as sort(), asort(), rsort() etc. Quote Link to comment https://forums.phpfreaks.com/topic/116082-ordering-an-output/#findComment-596885 Share on other sites More sharing options...
ecopetition Posted July 22, 2008 Author Share Posted July 22, 2008 The output isn't from an array. It's just data taken from a database table which is just printed, but i'm wondering if the data can be processed to arrange it first. Quote Link to comment https://forums.phpfreaks.com/topic/116082-ordering-an-output/#findComment-596893 Share on other sites More sharing options...
wildteen88 Posted July 22, 2008 Share Posted July 22, 2008 You can use the ODERY BY column_name ASC clause in your query to sort your results by a column. Quote Link to comment https://forums.phpfreaks.com/topic/116082-ordering-an-output/#findComment-596896 Share on other sites More sharing options...
revraz Posted July 22, 2008 Share Posted July 22, 2008 How are you pulling the data from the Database without using an array? Quote Link to comment https://forums.phpfreaks.com/topic/116082-ordering-an-output/#findComment-596901 Share on other sites More sharing options...
.josh Posted July 22, 2008 Share Posted July 22, 2008 How are you pulling the data from the Database without using an array? You don't need to use an array to pull or print info from a database, unless you plan on using the info later on after the loop. $sql = "select col1, col2 from table"; $result = mysql_query($sql); while ($info = mysql_fetch_row($result)) { echo "{$info[0]} {$info[1]} <br />"; } $info is an array but it's an array of the columns/data which isn't really relevant for ordering the rows. Quote Link to comment https://forums.phpfreaks.com/topic/116082-ordering-an-output/#findComment-596910 Share on other sites More sharing options...
ecopetition Posted July 22, 2008 Author Share Posted July 22, 2008 I dont know, I've kind of inherited this job from someone who left a project we were working on and am sort of hopeless at it just now. Here's the code that is at least printing the string: 'OUTPUT' => implode(', ', $output_text[ $outputs[$i]['output_id'] ]), (for the variables:) $outputs = $output_text = array(); Quote Link to comment https://forums.phpfreaks.com/topic/116082-ordering-an-output/#findComment-596920 Share on other sites More sharing options...
wildteen88 Posted July 23, 2008 Share Posted July 23, 2008 We'll need to see more code than that. Quote Link to comment https://forums.phpfreaks.com/topic/116082-ordering-an-output/#findComment-597694 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.