Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Sorting Sql Results In An Array Using Things Outside The Array To Sort Them?


I'm using PHP to connect to a database full of place names, and their associated post codes, latitude and longitude on the earth. A user types his or her post code into a form, plus a distance (in miles), and the script looks for other area codes (first half of the post code) within that distance.

I can do that fine, but the results are ordered alphabetically by postcode, and I want to order it by the distance. Problem here, is that the distance isn't part of the array taken from the database, it takes the latitude and longitude of the area it's on in the while loop, and calculates the distance between the user's post code and that one, but it's not part of the array, so I can't sort the array using it.

How can I sort it? Can I add the calculated distances to the array, and sort it using sort()? If yes, how do I add them to the array?

Here's the page, just to explain better what the script does: http://navimaker.org/ed/owain/results.php?postcode=gl15&distance=34
Mess around with the postcode and distance vars.

I'd put the source on here too but I'm doing all this over SSH and can't copy & paste very easily .




View Complete Forum Thread with Replies

Related Forum Messages:
Sorting An Array - Sort These Results According To Their Relevance.
I'm trying to make my own search page for my website and I have it gathering correct results exactly as it should, but I'd like to find a way to have it sort these results according to their relevance (makes mroe sense of course).

As it is now, it is simply pulling them from my database newest-to-oldest. The array elements are compiled like this..

type_of_item.id_#_of_item.hits_for_item.data

..so you can see that I have them all seperated by periods, then to print the data I just get the length that it is from the left and echo it out. I have all of that working, but I need to find a way to sort my array by the 3rd period seperated part...the hits. I want the items with the most hits at the top.

View Replies !
Sorting Array - Sort Them Through A Certain Part?
Say I have an array with elements like the following:

13,stringhere,anotherstring,1293
15,stringheretwo,anotherstringtwo,3494

Is there anyway I can sort them through a certain part? Eg, could I sort the above alphabetically through the third string along ("anotherstring" and "anotherstringtwo" would be affected).

View Replies !
Sort Array - Sorting On Date Of Images
I am sorting on date of images which are the thumbnail of the tutorial, now i call the array doing the date, which gives me a long list of tutorials, i would like to only list 2 from each day then a break with adver then list 2 more from another date etc, whats the best way to do this, right now it just lists all the tutorials in order well the first 7 but breaks for adver etc.

View Replies !
Sorting Multidimensional Array - Used Sort Function
I have the following multidimensional array:

Array ( [1] => Array ( [0] => 0 [1] => 2 ) [2] => Array ( [0] => 1 ) )

I would like to have the following array:

[1] 0
[2] 1
[1] 2

Is this possible to do?

View Replies !
Query Array, Sort Results And Display In Seperate Tables
The problem I have it breaking out the results and displaying them (broken out) alphabetically in seperate tables. For instance, I have generated (bookmarked) tables, one for each letter (A-Z) and want to display all recordsets with say, last name
beginning with "A" in one 2 column table, "B" in another 2 column table, and so on... each
table would have two columns (with 2 background colors alternating), each cell containing values of one recordset.

Even more tricky is if I have an odd number of cells, still generating the last cell with empty values (for asthetics). And can anyone say "sort" (yes, I am nuts)? The ability to sort the whole mess by any column value. I have looked at freeware and other third part apps, but they can only do what I already can do (mine is actually cleaner) but not as complicated.

View Replies !
Array Sorting - Get Records To Sort (highest Point To Lowest Point)
i have to retrieve some info from tables and then add all the fields together, then list out. 10 records per time, then got 2nd page, 3rd page..so on...

my problem is ..i can't get my records to sort(highest point to lowest point), then i decided to use array. PHP Code:

View Replies !
Sorting An Array Problem, (array/string Manipulation)
I have a function that I found on google, that goes through a directory and spits out a directory tree in an array, with arrays inside of arrays, and more and more arrays inside of arrays, depending on how many subdirectories are there.....

Here is a sample "directory tree" it spits out. My problem is wanting to be able to create a new array containing only the paths to all the subdirectories it finds from this array, so it is with array manipulation...

Not all paths are located in the topmost array's values, but some directories are within other subdirectories and so forth.. I'm stumped on how exactly to sort through this array, whether recursively or not to grab all the 'paths' in the array period. Code:

View Replies !
Sort Array - [2] => Array( [id] => 232, [zone] => C, [color] => Yellow )
Array:

=> Array( [id] => 64, [zone] => a, [color] => blue )[1] => Array( [id] => 17, [zone] => b, [color] => grey )
    [2] => Array( [id] => 232, [zone] => c, [color] => yellow )
    [3] => Array( [id] => 36, [zone] => a, [color] => red )
    [4] => Array( [id] => 178, [zone] => a, [color] => white )
    [5] => Array( [id] => 10, [zone] => c, [color] => blue )
    [6] => Array( [id] => 115, [zone] => a, [color] => orange )
    [7] => Array( [id] => 345, [zone] => a, [color] => black )
    [8] => Array( [id] => 19, [zone] => b, [color] => green )
    [9] => Array( [id] => 206, [zone] => a, [color] => red )

View Replies !
Array Sorting Blues....2 Dimensional Array
I have a 2 dimensional array where one col contains a Unix style date and the other contains a filename. I read through a directory to get this info. I can load the array and print it out just fine, but I can't seem to sort it using any of the sort functions! I want to reverse sort them, since they are news stories that I want to display in the correct order by date. When I try to sort I get a "Warning: Cannot compare arrays or objects" message. I have the feeling it's something stupid on my part but can't find any good examples anywhere.

Anyone have an idea about this?

P.S. I know a database would solve this but sadly it's not an option for me right now...

View Replies !
Sort The Array By The Values In Array[$i][0]
How would I go about sorting the following array, I've been looking at array_multisort but to be honest I'm either not fully understanding it or it's not capable of what I'm trying to do.

What I'd like to do is to sort the array by the values in array[$i][0] but I can't figure it out, the values being zzzz,a0,a1,00000000000000. PHP Code:

View Replies !
Sorting An Array With Another Array
I have an array that is an order of things:

array(23,54,1,45,12,9)

And then I have an array of values from the table. Within this array is an id which relates to the previous array. It holds quite alot of information so I'm hoping there might be an easy way, as opposed to the long and messy way, to sort this array with the values in the other array.

Looking through the array functions, I can't quite see it. Any advice on this one?

View Replies !
Sorting Array?
I have an array that has 3 keys and I want to sort the array by the values in the key called "key3" so which sort function do I use? array("key1"=>"hey", "key2"=>"hello", "key3"=>"hi")

View Replies !
Sorting A 3d Array
I am trying to sort the display url subarray and it works, however, the other arrays stay in there place which throws the whole thing off. How do I sort by displayurl and make the other sub arrays move with it? PHP Code:

View Replies !
Sorting An Array..
i've have the following array:

files['name'][1]
['size'][1]
['time'][1]
files['name'][2]
['size'][2]
['mtime'][2]
...etc.

how do I sort this array according to "time" index? so that, for
example, files['name'][0] would give "my_file.txt" that was last
created?

View Replies !
Sorting An Array - Add 1 To The Value Every Little While.
I've got a small problem. I have an array that looks something like this:$smthin = array (

"character1" => 0,
"character2" => 0,
"character3" => 0,
"character4" => 0,
"character5" => 0);

I add 1 to the value every little while. Then it may look like this:$smthin = array (

"character1" => 1,
"character2" => 6,
"character3" => 0,
"character4" => 1,
"character5" => 2);

And at this point I'd like to sort the array to look like following:$smthin = array (

"character2" => 6,
"character5" => 2,
"character1" => 1,
"character4" => 1,
"character3" => 0);

I don't think sort() function will help me with this. That would ruin the keys.

View Replies !
Sorting Array
I am trying to sort the array $showall below. I put the $DISTANCE variable first and I want it to sort numerical not alphabetically. No matter what sort function I put in (asort, fsort, usort) it still displays the same. DISTANCE is not a field in my table, it is being calculated within the WHILE loop. What sort should I be using and where exactly should it go?

View Replies !
Sorting Out An Array
Im trying to make show the final 5 entries. So im running a query from my db, i can make them show all.

I run sort, arsort or any sort at the query, but it completely disapears or it doesn't work at all.. Code:

View Replies !
Sorting A 2d Array
PHP Code:

function getDebtTop5($getTotalsArray) {

for ($row = 0; $row < count($getTotalsArray); $row++)
{
    for ($col = 0; $col < 2; $col++)
    {
        echo "<br>".$getTotalsArray[$row][$col];
    }
}
}

View Replies !
Sorting An Array
i have the following array:

files['name'][1]
['size'][1]
['time'][1]
files['name'][2]
['size'][2]
['mtime'][2]
...etc.

View Replies !
Array Sorting
I have an array for product items like so

[Item] => Array (
[ItemID] => 123456
[0] => Array
(
[Details] => Array
(
[Description] => This is an item
[Title] => An Item
[URL] => http://url.com
)
[Pricing] => Array
(
[Price] => 1.99
[Postage] => 10.99
)....

View Replies !
Sorting Array
I have an array like so:

Array (
[Ironwood] => Array (
[3Q07] => Array (
[Audio] => Ironwood-3Q07-Audio.mp3
)
)

[Thornburg_Management] => Array (
[2Q07] => Array (
[Audio] => Thornburg_Management-2Q07-Audio.wav
)
[1Q07] => Array (
[Audio] => Thornburg_Management-1Q07-Audio.mp3
[Commentary] => Thornburg_Management-1Q07-Commentary.pdf.

View Replies !
Array Sort By Value
I have an array that has the following structure:

Array
(
[0] => xml_make Object
(
[name] => Alfa Romeo
[totalItems] => 270
)

[1] => xml_make Object
(
[name] => Aston Martin
[totalItems] => 7
)

[2] => xml_make Object
(
[name] => Audi
[totalItems] => 948
)

[3] => xml_make Object
(
[name] => Austin
[totalItems] => 51
)

[4] => xml_make Object
(
[name] => BMW
[totalItems] => 2235
)
}

How can I sort the array by the value in total Items?

View Replies !
I Need To Sort An Array
Current Case:
I have a table in a database

PRODUCTS
--------------
product_id
product_name
product_category
product_order

I am trying to create a change order script. With Up/Down links.

So I run my querry and store the data in the database. So I end up with an
array ....

View Replies !
RSS Array Sort
I am pulling in a few RSS feeds into my site and I need to be able to sort the array I build by the pubdate of the feeds. The resulting array looks like this:

Array
(
    [0] => Array
        (
            [title] => Title of Feed
            [link] => link of feed
            [pubdate] =>  2007-05-04 00:00:00
            [description] =>  Description
        )

    [1] => Array
        (
            [title] => Title of Feed
            [link] => link of feed
            [pubdate] =>  2007-06-04 00:00:00
            [description] =>  Description
        )

I need to be able to sort by $theitems[$i]['pubdate'], how can I do that?

View Replies !
Sort An Array
How do we sort 3 dimensional array by sorting on 3 , 2 and 1st dimensions?

View Replies !
Sort An Array By Sub Key
If i have this array : PHP Code:

(
    [0] => Array
        (
            [id] => 9
            [date] => 2005
        )

    [1] => Array
        (
            [id] => 10
             [date] => 2002
        )

    [2] => Array
        (
            [id] => 11
            [date] => 2004
        )

)

Is there any function to sort it by date key ?

View Replies !
Array Sort
I've got an array with the following structure:

$process[0] => array("recordID" => 1, "name" => "matt");
$process[1] => array("recordID" => 2, "name" => "john");
etc

I need the process array sorting by record ID...... I've tried doing

asort($process)

but that doesnt work - I dont know how to access the elements inside the array to sort by..... any ideas?

View Replies !
Trying To Sort An Array
I want to sort an array using an associate key. How do I sort an array as the following: Code:

View Replies !
Sort PHP Array
Code:

$clientArray[$i]["CLIENT_CODE"]
$clientArray[$i]["CLIENT_NAME"]
$clientArray[$i]["SERVICE"]
$clientArray[$i]["HARDWARE"]
$clientArray[$i]["MUSIC"]
$clientArray[$i]["PURCHASE"]
$clientArray[$i]["INVOICE_TOT"]
$clientArray[$i]["POST"]
$clientArray[$i]["RECALL"]
$clientArray[$i]["FIRST_INV"]
$clientArray[$i]["GROUP_TYPE"]
$clientArray[$i]["END_DATE_S"]
$clientArray[$i]["MEMO"]

View Replies !
Sort Array
I've read the manual and looked at a few posts on this site as well as through goole, and I cannot get my head around sorting an array with the following data: Code:

View Replies !
Sorting Array Of Objects?
I'm reading an XML file using SimpleXML and xpath into an array. What I'd like to do is sort the array based on a specific element's value. For instance, an XML that has some elements like:

<CUST>
<NAME>ABC Co.</NAME>
<LVL>A1</LVL>
<STATE>CA</STATE>
</CUST>
<CUST>
<NAME>ACME</NAME>
<LVL>A2</LVL>
<STATE>CA</STATE>
</CUST>

is read into an array. Because I'm using SimpleXML, the array elements are each SimpleXML objects. I want to then sort the array based on the value of the LVL element (i.e. A1's, then A2's, etc.). Every item in the array will contain this element. Is this possible?

View Replies !
Sorting A Two Dimensional Array
I have an array, thus:

Array (
[0] => Array ( [Freq] => 28 [Name] => Tomato )
[1] => Array ( [Freq] => 4 [Name] => Banana )
[2] => Array ( [Freq] => 54 [Name] => Orange )
[3] => Array ( [Freq] => 24 [Name] => Eggplant )
[4] => Array ( [Freq] => 5 [Name] => Courgette )
[5] => Array ( [Freq] => 4 [Name] => Apple )
)

I would like to be able to sort it either by the Frequency or the Name
of the fruit or vegetable.

I just can't seem to get it to work. I'm sorry - I realise that this is
probably really easy but my brain isn't working today and the examples
on php.net seem incomprehensible to me.

View Replies !
Array Sorting Functions.
having some trouble understanding what is happening with some array
sorting functions. In all cases, my compare function is:
function compare($x, $y)
{
if ( $x[1] == $y[1] )
return 0;
else if ( $x[1] < $y[1] )
return -1;
else
return 1;
}
I started with this:
$contents = array( array( 'TIR', 'Tires', 100 ),
array( 'OIL', 'Oil', 10 ),
array( 'SPK', 'Spark Plugs', 4 ) );
echo '<br>XXX<br>'
foreach($contents as $r) {
var_export($r);
echo '<br>'
}
echo '<br>YYY<br>'
uasort($contents, 'compare');
foreach($contents as $r) {
var_export($r);
echo '<br>'
}
And the output, whether I use usort or uasort is always:
XXX
array ( 0 => 'TIR', 1 => 'Tires', 2 => 100, )
array ( 0 => 'OIL', 1 => 'Oil', 2 => 10, )
array ( 0 => 'SPK', 1 => 'Spark Plugs', 2 => 4, )

YYY
array ( 0 => 'OIL', 1 => 'Oil', 2 => 10, )
array ( 0 => 'SPK', 1 => 'Spark Plugs', 2 => 4, )
array ( 0 => 'TIR', 1 => 'Tires', 2 => 100, )
But if I use uksort I get:
XXX
array ( 0 => 'TIR', 1 => 'Tires', 2 => 100, )
array ( 0 => 'OIL', 1 => 'Oil', 2 => 10, )
array ( 0 => 'SPK', 1 => 'Spark Plugs', 2 => 4, )

YYY
array ( 0 => 'SPK', 1 => 'Spark Plugs', 2 => 4, )
array ( 0 => 'OIL', 1 => 'Oil', 2 => 10, )
array ( 0 => 'TIR', 1 => 'Tires', 2 => 100, )

But I cannot see why I get this reversal of order???

I then tried:
$contents = array( array( c=>'TIR', d=>'Tires', p=>100 ),
array( c=>'OIL', d=>'Oil', p=>10 ),
array( c=>'SPK', d=>'Spark Plugs', p=>4 ) );

View Replies !
Sorting A Multidimensional Array
I Have an array set as so:

$temparr[$i]['score'] = 3.4
$temparr[$i]['id'] = 1
$temparr[$i]['title'] = 'title'

$i loops the array populating it, but when I output the array, i would like to sort it by the 'score' value asc or desc, depending on what i want to show... what is the easiest way of achieving this?

View Replies !
Sorting 2D Array By Inner Array's Key
What is the most efficient way to do this for a fairly big array?

For example:

$arr[0][0]='apple';
$arr[0][1]='24';
$arr[1][0]='orange';
$arr[1][1]='2';
$arr[2][0]='banana';
$arr[2][1]='3451';

What would be the best way to sort that array by the inner array's 1 key?

View Replies !
Sorting An Array That Is A Little Messed Up?
I am trying to perform a sort of some data from a mysql database, by DATE. However, the original people who made it (and the entire website) were a little dense, and stored the dates as varchar(15) in the format ddmmyy.

I need to retrieve multiple attributes, but sort only by one of the them: con_date.

I have a if(sortby==relevance) ... elseif(sortby==age) condition. The relevance sort isn't a problem. It loops through the array and echos out (in relevance order) a headline, text, and the date in a readable format using a function that converts it: .....

View Replies !
Sorting Array By Its First Dimmension
A little question I need to chew on... If I have a 2 dimmensional array, with this structure:

array(1, date
type
name
2, date
type
name
3, date
type
name);

and I want to sort by the date, how would I go about doing this?

View Replies !
Multidimensional Array Sorting
I'm having some trouble sorting a multidimensional array I have created. The use of this sorting is to set up "standings", sorted by WINS descending, LOSSES ascending, and TIES descending. The array looks as such: Code:

View Replies !
Problem With Sorting Array
Let's say i have an array of data,for example;

$tasktimes = {0.6,1.2 ,0.3,1.0}. how can i sort this array from the smallest value to the biggest value? i mean like this,$tasktimes = {0.3,0.6,1.0,1.2}.

does php have any function for this?

View Replies !
Array Sorting - Register_globals Being Off In The PHP.ini, And Set It To ON
I'm setting up a wiki for use on our company intranet, and I've created a page that will pull information out of active directory, and publish it, so employees have an easy way of finding each others contact details. I've created the page by using PHP inside of the wiki page, which runs an LDAP query, this all works fine, and displays the information correctly in an unsorted format.

I would like to sort the information by employee name. I have the code, and it works in a plain PHP file perfectly, however, when I copy & paste the working code from the PHP file, into our wiki (Dokuwiki), the sort function fails to work. I've looked through a few options, such as register_globals being off in the PHP.ini, and set it to ON, but this hasn't helped. Below is a snip of my code, can anyone suggest a way to get this working in a wiki page?

View Replies !
Sorting Two Dimensional Array
I have a two dimensional array that I need to sort based on a total of values in the second dimension. The top level array has a part number and another array as its elements. The second array consists of defect types and defect quantity corresponding to the part number. I am able to sort the second defect array by defect type (so whichever type has the highest quantity shows up first) but I am not sure how to sort so that the parts with the highest total defects are first. Essentially I need to sort based on the total quantities in the second array, but I am not sure how to do that on the fly. Here is a print_r of the array.

Part#101 Array ( [Scratches] => 6 )
Part#102 Array ( [Scratches] => 174 [Handling] => 22 [Supplier Mold Defect] => 9 [Dirt] => 9 )
Part#103 Array ( [Scratches] => 167 [Dirt] => 116 [Handling] => 4 [Water Spots] => 3 [Supplier Mold Defect] => 1 )
Part#104 Array ( [Scratches] => 20 [Supplier Mold Defect] => 4 )

After sorting the part order should be:
Part#103 (291 total defects)
Part#102 (214 total defects)
Part#104 (24 total defects)
Part#101 (6 total defects)

View Replies !
Sorting An Object Array
I've got an array of objects. The print_r() looks like this: Code:

View Replies !
Problems With Sorting An Array
I have a page that's doing a search of a database, create an array and
displays it. And I have it displaying the array just fine, but when I
try to sort it, I get the error:

Warning: sort() expects parameter 1 to be array, null given in
/home/iestud/public_html/gto/search.php on line 43
(line 43 is the sort() function). Code:

View Replies !
Sorting A Mysql Array
The thing I want to do is take a mysql table, read it in a php file, sort it alphabeticly/numericly, and have it outputted onto the page in the form of a table.

I found 2 tutorials that I thought would help me. One allowed me to read a mysql table and output it on the screen... and another allowed me to sort a php array and output it, but unfortunatly I couldn't seem to get both to work together.

View Replies !
Customized Array Sorting
I've done some reading on this topic and it seems there is a way to do what I want, but I'm having a difficult time wrapping my head around how I can make it work.

I have an array which is made out of a list of files in a directory. I'd like to be able to customize the sorting of the array to match a predefined list, or variable somehow.

For instance, my files names are based system names, here's an example(not the actual names): Code:

View Replies !
Array Sorting (multidimensional)
I have an array:

array(2) { [0]=> array(1) { ["pageID"]=> string(1) "8" } [1]=> array(1) { ["thematch"]=> float(1.34) } [2]=> array(1) { ["table"]=> string(2) "ct" } [3]=> array(1) { ["pageID"]=> string(1) "6" } [4]=> array(1) { ["thematch"]=> float(1.33) } [5]=> array(1) { ["table"]=> string(2) "ct" } }

The problem - I want to sort this array by the second level key value of "thematch".

I've tried using the various sort, ksort, asort etc but to no avail.

Can someone suggest a way to sort this array by the value (in descending order) of that key?

View Replies !
Sorting A Multi Array
Array:

(
[czero] => Array
(
[game_type] => czero
[game_label] => Condition Zero
[count] => 2
)
[cstrike] => Array
(
[game_type] => cstrike
[game_label] => Counter-Strike
[count] => 3
)
[dod] => Array

View Replies !
Sorting An Array Of Dates
I have an array of dates formatted like: 7/17/2007, now I want to sort them from the most current date tot he furtherest from now, and let's say the array is like this:

dates[0] = 7/17/2007
dates[1] = 7/22/2007
datesp2] = 6/22/2007
dates[3] = 2/22/2008.

View Replies !
Sorting Multidimensional Array
I have a multidimensional array that i need to sort by value. An example of the array is as follows

$myarray[0]['price']=1400;
$myarray[0]['txt']="my arrays txt";
$myarray[0]['acer']="5";

$myarray[1]['price']=1500;
$myarray[1]['txt']="my arrays txt 2";
$myarray[1]['acer']="1";

View Replies !
Array Sorting Question
I have mysql table:

+----+---------+
| 1 | value1 |
+----+---------+
| 2 | value2 |
+----+---------+
| 3 | value3 |
+----+---------+
| 4 | value4 |
+----+---------+

What is the best way to sort results from:

$query = mysql_query("SELECT * FROM table");

into array like this:

array(
1 => 'value1',
2 => 'value2',
3 => 'value3',
4 => 'value4'));

View Replies !
Using A Pseudocode To Sort An Array
I want to sort an array, but the problem is that I can't use sort, rsort, asort, etc. So I want a Pseudocode to order the array.

View Replies !
Sort() Messed Up My Array!
I have an assosiative array with "key"s and "value"s which I get by using array_count_values() on $array.

$array is an array of numbers, for example 1, 0, 0, -5.

Here's some code:

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved