473,657 Members | 2,530 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 2281
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
2829
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 code is included below. My question is, is there a better way to allocate the memory for the...
5
28037
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 functions like those in C#, which kick a*s. TIA
7
26131
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 size. Any idea how can I do
6
6602
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 can assing output data to variables in main program and do some manipulation. Can any body guide...
20
2304
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
2528
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
1577
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
5608
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 getting this to work using the System.Array.ForEach method. This may be partially because I am not very...
15
1743
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
8421
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8742
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8621
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6177
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.