PHP group SQL results by a column












0















I am hoping someone can help. I am trying to build something and I would like PHP/MySQL to group results. Here is an example of my table:



id   service service_info service_crew
num varchar longtext varchar


In service_crew, the format will be FirstName.LastName but sometimes there can be multiple, such as: John.Doe,Sam.Smith,Alex.Jones or Jordan.Smith



What I would like to do is group results per crew member so an email can be sent with the relevant info for each of the services they will work that day, but due to the amount of crew members and a quick changing environment, it is not possible to have a list of all crew members stored, so it will need to work purely based on the information in this database table.



I hope this makes sense?



Thanks!










share|improve this question























  • provide your expected output

    – fa06
    Nov 23 '18 at 6:25











  • @fa06 I am would like each crew members workings to be available in an array so that the PHP script will automatically be able to send an email to each of them containing all of the services they are due to work. I can handle the email part I just need a way of running maybe a "foreach" for each crew member and then each of their workings?

    – Simon
    Nov 23 '18 at 6:31













  • service_crew is hopefully not a CSV? Please provide sample data.

    – user3783243
    Nov 23 '18 at 6:33













  • @Simon Better you store the email_Id's of employees also in DB. It will be a feasible solution

    – Aravind Bhat K
    Nov 23 '18 at 6:33






  • 1





    Yes, please go the the other route. If you must you could use a CSV parser, but this really is a bad design and will bite you further down the road.

    – user3783243
    Nov 23 '18 at 6:50


















0















I am hoping someone can help. I am trying to build something and I would like PHP/MySQL to group results. Here is an example of my table:



id   service service_info service_crew
num varchar longtext varchar


In service_crew, the format will be FirstName.LastName but sometimes there can be multiple, such as: John.Doe,Sam.Smith,Alex.Jones or Jordan.Smith



What I would like to do is group results per crew member so an email can be sent with the relevant info for each of the services they will work that day, but due to the amount of crew members and a quick changing environment, it is not possible to have a list of all crew members stored, so it will need to work purely based on the information in this database table.



I hope this makes sense?



Thanks!










share|improve this question























  • provide your expected output

    – fa06
    Nov 23 '18 at 6:25











  • @fa06 I am would like each crew members workings to be available in an array so that the PHP script will automatically be able to send an email to each of them containing all of the services they are due to work. I can handle the email part I just need a way of running maybe a "foreach" for each crew member and then each of their workings?

    – Simon
    Nov 23 '18 at 6:31













  • service_crew is hopefully not a CSV? Please provide sample data.

    – user3783243
    Nov 23 '18 at 6:33













  • @Simon Better you store the email_Id's of employees also in DB. It will be a feasible solution

    – Aravind Bhat K
    Nov 23 '18 at 6:33






  • 1





    Yes, please go the the other route. If you must you could use a CSV parser, but this really is a bad design and will bite you further down the road.

    – user3783243
    Nov 23 '18 at 6:50
















0












0








0








I am hoping someone can help. I am trying to build something and I would like PHP/MySQL to group results. Here is an example of my table:



id   service service_info service_crew
num varchar longtext varchar


In service_crew, the format will be FirstName.LastName but sometimes there can be multiple, such as: John.Doe,Sam.Smith,Alex.Jones or Jordan.Smith



What I would like to do is group results per crew member so an email can be sent with the relevant info for each of the services they will work that day, but due to the amount of crew members and a quick changing environment, it is not possible to have a list of all crew members stored, so it will need to work purely based on the information in this database table.



I hope this makes sense?



Thanks!










share|improve this question














I am hoping someone can help. I am trying to build something and I would like PHP/MySQL to group results. Here is an example of my table:



id   service service_info service_crew
num varchar longtext varchar


In service_crew, the format will be FirstName.LastName but sometimes there can be multiple, such as: John.Doe,Sam.Smith,Alex.Jones or Jordan.Smith



What I would like to do is group results per crew member so an email can be sent with the relevant info for each of the services they will work that day, but due to the amount of crew members and a quick changing environment, it is not possible to have a list of all crew members stored, so it will need to work purely based on the information in this database table.



I hope this makes sense?



Thanks!







php mysql arrays






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 6:23









SimonSimon

1




1













  • provide your expected output

    – fa06
    Nov 23 '18 at 6:25











  • @fa06 I am would like each crew members workings to be available in an array so that the PHP script will automatically be able to send an email to each of them containing all of the services they are due to work. I can handle the email part I just need a way of running maybe a "foreach" for each crew member and then each of their workings?

    – Simon
    Nov 23 '18 at 6:31













  • service_crew is hopefully not a CSV? Please provide sample data.

    – user3783243
    Nov 23 '18 at 6:33













  • @Simon Better you store the email_Id's of employees also in DB. It will be a feasible solution

    – Aravind Bhat K
    Nov 23 '18 at 6:33






  • 1





    Yes, please go the the other route. If you must you could use a CSV parser, but this really is a bad design and will bite you further down the road.

    – user3783243
    Nov 23 '18 at 6:50





















  • provide your expected output

    – fa06
    Nov 23 '18 at 6:25











  • @fa06 I am would like each crew members workings to be available in an array so that the PHP script will automatically be able to send an email to each of them containing all of the services they are due to work. I can handle the email part I just need a way of running maybe a "foreach" for each crew member and then each of their workings?

    – Simon
    Nov 23 '18 at 6:31













  • service_crew is hopefully not a CSV? Please provide sample data.

    – user3783243
    Nov 23 '18 at 6:33













  • @Simon Better you store the email_Id's of employees also in DB. It will be a feasible solution

    – Aravind Bhat K
    Nov 23 '18 at 6:33






  • 1





    Yes, please go the the other route. If you must you could use a CSV parser, but this really is a bad design and will bite you further down the road.

    – user3783243
    Nov 23 '18 at 6:50



















provide your expected output

– fa06
Nov 23 '18 at 6:25





provide your expected output

– fa06
Nov 23 '18 at 6:25













@fa06 I am would like each crew members workings to be available in an array so that the PHP script will automatically be able to send an email to each of them containing all of the services they are due to work. I can handle the email part I just need a way of running maybe a "foreach" for each crew member and then each of their workings?

– Simon
Nov 23 '18 at 6:31







@fa06 I am would like each crew members workings to be available in an array so that the PHP script will automatically be able to send an email to each of them containing all of the services they are due to work. I can handle the email part I just need a way of running maybe a "foreach" for each crew member and then each of their workings?

– Simon
Nov 23 '18 at 6:31















service_crew is hopefully not a CSV? Please provide sample data.

– user3783243
Nov 23 '18 at 6:33







service_crew is hopefully not a CSV? Please provide sample data.

– user3783243
Nov 23 '18 at 6:33















@Simon Better you store the email_Id's of employees also in DB. It will be a feasible solution

– Aravind Bhat K
Nov 23 '18 at 6:33





@Simon Better you store the email_Id's of employees also in DB. It will be a feasible solution

– Aravind Bhat K
Nov 23 '18 at 6:33




1




1





Yes, please go the the other route. If you must you could use a CSV parser, but this really is a bad design and will bite you further down the road.

– user3783243
Nov 23 '18 at 6:50







Yes, please go the the other route. If you must you could use a CSV parser, but this really is a bad design and will bite you further down the road.

– user3783243
Nov 23 '18 at 6:50














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441532%2fphp-group-sql-results-by-a-column%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441532%2fphp-group-sql-results-by-a-column%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?