473,574 Members | 2,529 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array manipulation

Hi,

I have an array in the following format :

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

[0] =Array
(
[GROUP_CONCAT(DI STINCT destination_ids )] =9
)

)

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

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

)

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

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

)

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

[0] =Array
(
[GROUP_CONCAT(DI STINCT 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(DI STINCT 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 2279
fel
On May 31, 10:37 am, lukemack <lukemst...@gma il.comwrote:
Hi,

I have an array in the following format :

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

[0] =Array
(
[GROUP_CONCAT(DI STINCT destination_ids )] =9
)

)

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

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

)

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

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

)

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

[0] =Array
(
[GROUP_CONCAT(DI STINCT 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(DI STINCT 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=ar ray();
foreach($main_a rray as $item){
$stuff = explode(',',$it em['GROUP_CONCAT(D ISTINCT 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
2823
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 decode. I have done a conversion to pyrex and have gotten it down to about 2 seconds to run both encode and decode. An an excerpt from the pyrex...
5
28035
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 y'all have any pre-written code to do this? Psuedo-Hopeless Request- Dear Microsoft: It would be cool if VBA had more robust string manipulation...
7
26124
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)); printf("Size : %d", sizeof(a)); this actually gives me 4 bytes, which essentially is the sizeof the pointer. But I want to know the actual memory...
6
6598
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 oci8 routines. The output resides in a structure defined within the sub-routine. Now I want this structure to be returned to main program so that I...
20
2294
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
2525
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 array has 255, I set the same elements in the other array to 255 and visa versa. Does anyone know how to do this without using for loops? Sincerely,
8
1576
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 int d;
9
5603
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 String.Format("'{0}'", value) End Function Basically, I just want to surround each value with single quotes. However, I am having trouble...
15
1736
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
7815
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8077
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7828
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8113
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5316
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3765
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2253
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.