473,326 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Array manipulation

Hi,

I have an array in the following format :

Array
(
[0] =Array
(
[itineries] =Array
(
[ship_id] =1
)

[0] =Array
(
[GROUP_CONCAT(DISTINCT destination_ids)] =9
)

)

[1] =Array
(
[itineries] =Array
(
[ship_id] =6
)

[0] =Array
(
[GROUP_CONCAT(DISTINCT destination_ids)] =9,2,21
)

)

[2] =Array
(
[itineries] =Array
(
[ship_id] =7
)

[0] =Array
(
[GROUP_CONCAT(DISTINCT destination_ids)] =9,12,4
)

)

[3] =Array
(
[itineries] =Array
(
[ship_id] =8
)

[0] =Array
(
[GROUP_CONCAT(DISTINCT destination_ids)] =>
15,23,26,15,19,26
)

)

Yes, I'm querying a badly designed database in which destination_ids
are stored as comma separated fields in a single field. I didnt design
it and changing it is unfortunately not an option, at least for now.
The itineraries table (the source of the array) is the only point in
the database where the destination and ship_id are linked so I need to
figure out a way of converting the above array so that i have a list
of ships per destination id, instead of the other way round.

the query i am using is $query = 'SELECT ship_id,
GROUP_CONCAT(DISTINCT destination_ids) FROM itineries GROUP BY
ship_id;';

if i change this query to group by distinct destination ids, i still
end up with some destination id entries with more that one value
(comma separated).

can anyone suggest how i can manipulate the above array using array
functions to get the resultset i need?

many thanks,

lukemack.

May 31 '07 #1
1 2263
fel
On May 31, 10:37 am, lukemack <lukemst...@gmail.comwrote:
Hi,

I have an array in the following format :

Array
(
[0] =Array
(
[itineries] =Array
(
[ship_id] =1
)

[0] =Array
(
[GROUP_CONCAT(DISTINCT destination_ids)] =9
)

)

[1] =Array
(
[itineries] =Array
(
[ship_id] =6
)

[0] =Array
(
[GROUP_CONCAT(DISTINCT destination_ids)] =9,2,21
)

)

[2] =Array
(
[itineries] =Array
(
[ship_id] =7
)

[0] =Array
(
[GROUP_CONCAT(DISTINCT destination_ids)] =9,12,4
)

)

[3] =Array
(
[itineries] =Array
(
[ship_id] =8
)

[0] =Array
(
[GROUP_CONCAT(DISTINCT destination_ids)] =>
15,23,26,15,19,26
)

)

Yes, I'm querying a badly designed database in which destination_ids
are stored as comma separated fields in a single field. I didnt design
it and changing it is unfortunately not an option, at least for now.
The itineraries table (the source of the array) is the only point in
the database where the destination and ship_id are linked so I need to
figure out a way of converting the above array so that i have a list
of ships per destination id, instead of the other way round.

the query i am using is $query = 'SELECT ship_id,
GROUP_CONCAT(DISTINCT destination_ids) FROM itineries GROUP BY
ship_id;';

if i change this query to group by distinct destination ids, i still
end up with some destination id entries with more that one value
(comma separated).

can anyone suggest how i can manipulate the above array using array
functions to get the resultset i need?

many thanks,

lukemack.

there are 2 answers for your question.
first:
------

php.net/explode

second:
-------

$other_array=array();
foreach($main_array as $item){
$stuff = explode(',',$item['GROUP_CONCAT(DISTINCT destination_ids)']);
foreach($stuff as $thing){
$other_array[$item[$thing]][]=$item['ship_id'];
}
print_r($other_array);

which answer do you preffer?

Jun 1 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Chris Lambacher | last post by:
Hi, I have to do some data manipulation that needs to be fast. I had a generator approach (that was faster than a list approch) which was taking approximately 5 seconds to run both encode and...
5
by: Johnny Meredith | last post by:
Is there a function in VBA to convert a string to an array of characters. I'm looking for the exact same functionality as the ToCharArray() method in C#. If this functionality does not exist, do...
7
by: Jamil Anwar Zaman | last post by:
If I dynamically allocate memory to a pointer, then is it possible to see afterwards what is the memory size the pointer is looking at. e.g int SIZE = 10; int *a = malloc(SIZE*sizeof(int));...
6
by: Neo | last post by:
Dear All, I want to know how a subroutine should return an array of values to the main program. From the main program, I call a sub-routine 'get_sql' which then fetches data from oracle db using...
20
by: K.M. Jr. | last post by:
Hi all, Consider this line - char s = "\0"; Does this initialize all array elements to zero ? Thanks.
12
by: Sheldon | last post by:
Hi, I have two arrays that are of the same dimension but having 3 different values: 255, 1 or 2. I would like to set all the positions in both arrays having 255 to be equal, i.e., where one...
8
by: Francisco | last post by:
Hello, Is there any code faster than this array position manipulation (some code omitted for brevity)?: internal struct TreeNodeTableItem { public int a; public int b; public int c; public...
9
by: Nathan Sokalski | last post by:
I am trying to use the System.Array.ForEach method in VB.NET. The action that I want to perform on each of the Array values is: Private Function AddQuotes(ByVal value As String) As String Return...
15
by: DL | last post by:
say, we have the following: // declare an array myArray = ; // short hand? same as myArray = new Array ? // populate it myArray = 0; myArray = 0; myArray = 1; myArray = 0;
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.