I am querying data from a database. All of the data is stored in one column so I have: $data = $row['names']; So now $data contains the data from the `names` column. Is there anyway I could sort the data in the $data variable alphabeticly from A to Z? Thank you.
I'm sorry but you did not understand my question. The data is all in one column in one row. Like if the database is a 5 X 5 grid, location 1 x 5 contains: bob, jill, randy, rick, john, abby. I need to sort that data (the names are separated by commas) alphabeticly. Is this possible?
Checkout the php function sort(); An example: <?php $data = array(q,w,x,e,r,t,y,u,i,o,p,g,f,d,h,s,a,j,k,l,z,c,v,b,n,m); sort($data); foreach ($data as $key => $val) { echo "" . $val . "\n"; } ?> PHP: Will echo out: a b c d e f g h i j k l m n o p q r s t u v w y z So you could try this: $data = array($row['names']); sort($data); foreach ($data as $key => $val) { echo "" . $val . "\n"; } PHP:
You'll have to store the result in a variable. Break it down using the coma and a space as the delimeter. Store each word in an array. Then sort that.