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. 1 2217
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? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
by: K.M. Jr. |
last post by:
Hi all,
Consider this line -
char s = "\0";
Does this initialize all array elements to zero ?
Thanks.
|
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...
|
by: Francisco |
last post by:
Hello,
Is there any code faster than this array position manipulation (some
code omitted for brevity)?:
internal struct TreeNodeTableItem {...
|
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...
|
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;...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
| |