Re: Sorting
| From: | Oliver Heinisch | Date: | Wed, 20 Mar 2002 11:20:54 +0000 |
| Subject: | Re: Sorting | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-89313@lists.php.net to get a copy of this message | ||
At 20.03.2002 16:29, you wrote:
Hii, Actually i want to sort the files form mysql database using php sorting.I can get the correct result using php sorting if the data's are stored in the array like this format. $temp=array("apple","Orange","Gova") please tell me how i will store the field details in a array fetched from mysql database even if you could sort the data with the correct selectf.e. select * from your_db where something='tru' order by the_field_you_wnt_to_sort, the method you requested is something like while($res=result_from_db_select) (sorry for result_from_db_select but as I´m using objects for databaseactions, I don´t know the exact commands maybe mysql_fetch_row) { for($i=0; $i < count($res); $i++) // counts all fields that come back {
$temp[$i] = $res[$i];} } if you have a named array, you could also use an array for the names f.e. $arraynames=array("first_col","second_col","third_col") the your code would like while($res=result_from_db_select) { for($i=0; $i < count($res); $i++) // counts all fields that come back {
$temp[$arraynames[$i]] = $res[$i];} } HTH Oliver