Fetch rows and check if has same value
I'm very new to coding and trying to learn PHP and MYSQL. What I'm trying to do is, grouping the same CustomerID querys in the same table while making an echo. At the moment, my code echos all the querys seperated. I have a table like
ID CustomerID DATE Company
1 1 2018-11-19 A
2 1 2018-11-19 A
3 2 2018-11-19 B
4 3 2018-11-19 C
5 4 2018-11-19 D
6 4 2018-11-19 D
My code
$query = "SELECT `customers`.ID, `customers`.customerid, `customers`.date
FROM `customers` WHERE month(DATE)= month(CURRENT_DATE()) AND YEAR(DATE) = YEAR(CURRENT_DATE());
$result = $mysqli->query($query);
while($resultquery = $result->fetch_array())
{
$queryresult = $resultquery;
}
if (!empty($queryresult)) {
foreach($queryresult as $queryresults)
{
$id = $queryresults['id'];
$customerid = $queryresults['customerid'];
$date = $queryresults['date'];
?>
Then I echo it and the result is
Company Name: A
ID CustomerID DATE
1 1 2018-11-19
Company Name: A
ID CustomerID DATE
2 1 2018-11-19
Company Name: B
ID CustomerID DATE
3 2 2018-11-19
Company Name: C
ID CustomerID DATE
4 3 2018-11-19
<?php }} ?>
Etc..
But what I want is to compare customerID's and if there is more than one with same id, echo them as a group in the table.
Company Name: A
ID CustomerID DATE
1 1 2018-11-19
2 1 2018-11-19
Company Name: B
ID CustomerID DATE
3 2 2018-11-19
Company Name: C
ID CustomerID DATE
4 3 2018-11-19
I made an sql query with GROUP_CONCAT and used SEPARATOR '|') to group the result, it works but I dont think its the best to achieve this, so please help. Thank you
php mysql compare fetch
|
show 1 more comment
I'm very new to coding and trying to learn PHP and MYSQL. What I'm trying to do is, grouping the same CustomerID querys in the same table while making an echo. At the moment, my code echos all the querys seperated. I have a table like
ID CustomerID DATE Company
1 1 2018-11-19 A
2 1 2018-11-19 A
3 2 2018-11-19 B
4 3 2018-11-19 C
5 4 2018-11-19 D
6 4 2018-11-19 D
My code
$query = "SELECT `customers`.ID, `customers`.customerid, `customers`.date
FROM `customers` WHERE month(DATE)= month(CURRENT_DATE()) AND YEAR(DATE) = YEAR(CURRENT_DATE());
$result = $mysqli->query($query);
while($resultquery = $result->fetch_array())
{
$queryresult = $resultquery;
}
if (!empty($queryresult)) {
foreach($queryresult as $queryresults)
{
$id = $queryresults['id'];
$customerid = $queryresults['customerid'];
$date = $queryresults['date'];
?>
Then I echo it and the result is
Company Name: A
ID CustomerID DATE
1 1 2018-11-19
Company Name: A
ID CustomerID DATE
2 1 2018-11-19
Company Name: B
ID CustomerID DATE
3 2 2018-11-19
Company Name: C
ID CustomerID DATE
4 3 2018-11-19
<?php }} ?>
Etc..
But what I want is to compare customerID's and if there is more than one with same id, echo them as a group in the table.
Company Name: A
ID CustomerID DATE
1 1 2018-11-19
2 1 2018-11-19
Company Name: B
ID CustomerID DATE
3 2 2018-11-19
Company Name: C
ID CustomerID DATE
4 3 2018-11-19
I made an sql query with GROUP_CONCAT and used SEPARATOR '|') to group the result, it works but I dont think its the best to achieve this, so please help. Thank you
php mysql compare fetch
Your query contains a syntax error; a missing closing quote. Is that just a bad paste?
– Funk Forty Niner
Nov 20 '18 at 3:05
You could store the results in the array based off thecustomerid
, ie$queryresult[$resultquery['customerid'] = $resultquery;
. Then you can loop over those to create your groups
– Sean
Nov 20 '18 at 3:19
@FunkFortyNiner yes it is. I have closing quote in my file.
– Alper Köse
Nov 20 '18 at 3:38
@Sean can you re-write my code with an explanation please? I dont know how to loop exactly and get the data from it. Thank you
– Alper Köse
Nov 20 '18 at 3:40
I don't see any of your code pastforeach($queryresult as $queryresults) {
, so I don't how I can re-write the code. I don't see whereCompany Name: A
is coming from
– Sean
Nov 20 '18 at 3:44
|
show 1 more comment
I'm very new to coding and trying to learn PHP and MYSQL. What I'm trying to do is, grouping the same CustomerID querys in the same table while making an echo. At the moment, my code echos all the querys seperated. I have a table like
ID CustomerID DATE Company
1 1 2018-11-19 A
2 1 2018-11-19 A
3 2 2018-11-19 B
4 3 2018-11-19 C
5 4 2018-11-19 D
6 4 2018-11-19 D
My code
$query = "SELECT `customers`.ID, `customers`.customerid, `customers`.date
FROM `customers` WHERE month(DATE)= month(CURRENT_DATE()) AND YEAR(DATE) = YEAR(CURRENT_DATE());
$result = $mysqli->query($query);
while($resultquery = $result->fetch_array())
{
$queryresult = $resultquery;
}
if (!empty($queryresult)) {
foreach($queryresult as $queryresults)
{
$id = $queryresults['id'];
$customerid = $queryresults['customerid'];
$date = $queryresults['date'];
?>
Then I echo it and the result is
Company Name: A
ID CustomerID DATE
1 1 2018-11-19
Company Name: A
ID CustomerID DATE
2 1 2018-11-19
Company Name: B
ID CustomerID DATE
3 2 2018-11-19
Company Name: C
ID CustomerID DATE
4 3 2018-11-19
<?php }} ?>
Etc..
But what I want is to compare customerID's and if there is more than one with same id, echo them as a group in the table.
Company Name: A
ID CustomerID DATE
1 1 2018-11-19
2 1 2018-11-19
Company Name: B
ID CustomerID DATE
3 2 2018-11-19
Company Name: C
ID CustomerID DATE
4 3 2018-11-19
I made an sql query with GROUP_CONCAT and used SEPARATOR '|') to group the result, it works but I dont think its the best to achieve this, so please help. Thank you
php mysql compare fetch
I'm very new to coding and trying to learn PHP and MYSQL. What I'm trying to do is, grouping the same CustomerID querys in the same table while making an echo. At the moment, my code echos all the querys seperated. I have a table like
ID CustomerID DATE Company
1 1 2018-11-19 A
2 1 2018-11-19 A
3 2 2018-11-19 B
4 3 2018-11-19 C
5 4 2018-11-19 D
6 4 2018-11-19 D
My code
$query = "SELECT `customers`.ID, `customers`.customerid, `customers`.date
FROM `customers` WHERE month(DATE)= month(CURRENT_DATE()) AND YEAR(DATE) = YEAR(CURRENT_DATE());
$result = $mysqli->query($query);
while($resultquery = $result->fetch_array())
{
$queryresult = $resultquery;
}
if (!empty($queryresult)) {
foreach($queryresult as $queryresults)
{
$id = $queryresults['id'];
$customerid = $queryresults['customerid'];
$date = $queryresults['date'];
?>
Then I echo it and the result is
Company Name: A
ID CustomerID DATE
1 1 2018-11-19
Company Name: A
ID CustomerID DATE
2 1 2018-11-19
Company Name: B
ID CustomerID DATE
3 2 2018-11-19
Company Name: C
ID CustomerID DATE
4 3 2018-11-19
<?php }} ?>
Etc..
But what I want is to compare customerID's and if there is more than one with same id, echo them as a group in the table.
Company Name: A
ID CustomerID DATE
1 1 2018-11-19
2 1 2018-11-19
Company Name: B
ID CustomerID DATE
3 2 2018-11-19
Company Name: C
ID CustomerID DATE
4 3 2018-11-19
I made an sql query with GROUP_CONCAT and used SEPARATOR '|') to group the result, it works but I dont think its the best to achieve this, so please help. Thank you
php mysql compare fetch
php mysql compare fetch
edited Nov 20 '18 at 3:53
Alper Köse
asked Nov 20 '18 at 3:04


Alper KöseAlper Köse
156
156
Your query contains a syntax error; a missing closing quote. Is that just a bad paste?
– Funk Forty Niner
Nov 20 '18 at 3:05
You could store the results in the array based off thecustomerid
, ie$queryresult[$resultquery['customerid'] = $resultquery;
. Then you can loop over those to create your groups
– Sean
Nov 20 '18 at 3:19
@FunkFortyNiner yes it is. I have closing quote in my file.
– Alper Köse
Nov 20 '18 at 3:38
@Sean can you re-write my code with an explanation please? I dont know how to loop exactly and get the data from it. Thank you
– Alper Köse
Nov 20 '18 at 3:40
I don't see any of your code pastforeach($queryresult as $queryresults) {
, so I don't how I can re-write the code. I don't see whereCompany Name: A
is coming from
– Sean
Nov 20 '18 at 3:44
|
show 1 more comment
Your query contains a syntax error; a missing closing quote. Is that just a bad paste?
– Funk Forty Niner
Nov 20 '18 at 3:05
You could store the results in the array based off thecustomerid
, ie$queryresult[$resultquery['customerid'] = $resultquery;
. Then you can loop over those to create your groups
– Sean
Nov 20 '18 at 3:19
@FunkFortyNiner yes it is. I have closing quote in my file.
– Alper Köse
Nov 20 '18 at 3:38
@Sean can you re-write my code with an explanation please? I dont know how to loop exactly and get the data from it. Thank you
– Alper Köse
Nov 20 '18 at 3:40
I don't see any of your code pastforeach($queryresult as $queryresults) {
, so I don't how I can re-write the code. I don't see whereCompany Name: A
is coming from
– Sean
Nov 20 '18 at 3:44
Your query contains a syntax error; a missing closing quote. Is that just a bad paste?
– Funk Forty Niner
Nov 20 '18 at 3:05
Your query contains a syntax error; a missing closing quote. Is that just a bad paste?
– Funk Forty Niner
Nov 20 '18 at 3:05
You could store the results in the array based off the
customerid
, ie $queryresult[$resultquery['customerid'] = $resultquery;
. Then you can loop over those to create your groups– Sean
Nov 20 '18 at 3:19
You could store the results in the array based off the
customerid
, ie $queryresult[$resultquery['customerid'] = $resultquery;
. Then you can loop over those to create your groups– Sean
Nov 20 '18 at 3:19
@FunkFortyNiner yes it is. I have closing quote in my file.
– Alper Köse
Nov 20 '18 at 3:38
@FunkFortyNiner yes it is. I have closing quote in my file.
– Alper Köse
Nov 20 '18 at 3:38
@Sean can you re-write my code with an explanation please? I dont know how to loop exactly and get the data from it. Thank you
– Alper Köse
Nov 20 '18 at 3:40
@Sean can you re-write my code with an explanation please? I dont know how to loop exactly and get the data from it. Thank you
– Alper Köse
Nov 20 '18 at 3:40
I don't see any of your code past
foreach($queryresult as $queryresults) {
, so I don't how I can re-write the code. I don't see where Company Name: A
is coming from– Sean
Nov 20 '18 at 3:44
I don't see any of your code past
foreach($queryresult as $queryresults) {
, so I don't how I can re-write the code. I don't see where Company Name: A
is coming from– Sean
Nov 20 '18 at 3:44
|
show 1 more comment
1 Answer
1
active
oldest
votes
Map your data in a key-value array with Company as key (include company in the query:
$query = "SELECT customers
.ID, customers
.customerid, customers
.date, company
FROM customers
WHERE month(DATE)= month(CURRENT_DATE()) AND YEAR(DATE) = YEAR(CURRENT_DATE())";
$query = "SELECT `customers`.ID, `customers`.customerid, `customers`.date
FROM `customers` WHERE month(DATE)= month(CURRENT_DATE()) AND YEAR(DATE) = YEAR(CURRENT_DATE());
Then simplify the data collection using a key to group items:
$result = $mysqli->query($query);
$queryresult = ;
while($resultquery = $result->fetch_array())
{
$company = $resultquery['company'];
if (array_key_exists($company,$queryresult){
@$queryresult[$company] = ;
}
@$queryresult[$company] = $resultquery;
}
An then you can present the information using foreach:
foreach($queryresult as $company => $items){
// header by company
echo "Company Name: $company n";
echo "ID CustomerID DATEn";
foreach($items as $item){
// items in company
echo "{$item['id']} {$item['customerid']} {$item['date']}n";
}
}
Thanks for helping but I get that error; Warning: Illegal offset type in report.php on line 54 $queryresult[$resultquery['group'] = $resultquery;
– Alper Köse
Nov 20 '18 at 4:55
You can add @ at@$queryresult[$company] = $resultquery;
to avoid this warning. It's because you are creating a new inexistent key for each group. Otherwise you can do a key check. I updated the example code.
– F.Igor
Nov 20 '18 at 5:28
The code works now I made a mistake while implementing it though it does not groups the company. It doesnt show the second query for the same company. There should be 5 record outputs which, 2 A company, 1 B, 2 C, 1 D but its like A1 B1 C1 D1
– Alper Köse
Nov 20 '18 at 6:43
I changed if (array_key_exists($company,$queryresult)) { @$queryresult[$company] = ; to if (array_key_exists($customerid,$queryresult)) { @$queryresult[$customerid] = ; and it works now. Thank you very much!
– Alper Köse
Nov 20 '18 at 7:02
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385615%2ffetch-rows-and-check-if-has-same-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Map your data in a key-value array with Company as key (include company in the query:
$query = "SELECT customers
.ID, customers
.customerid, customers
.date, company
FROM customers
WHERE month(DATE)= month(CURRENT_DATE()) AND YEAR(DATE) = YEAR(CURRENT_DATE())";
$query = "SELECT `customers`.ID, `customers`.customerid, `customers`.date
FROM `customers` WHERE month(DATE)= month(CURRENT_DATE()) AND YEAR(DATE) = YEAR(CURRENT_DATE());
Then simplify the data collection using a key to group items:
$result = $mysqli->query($query);
$queryresult = ;
while($resultquery = $result->fetch_array())
{
$company = $resultquery['company'];
if (array_key_exists($company,$queryresult){
@$queryresult[$company] = ;
}
@$queryresult[$company] = $resultquery;
}
An then you can present the information using foreach:
foreach($queryresult as $company => $items){
// header by company
echo "Company Name: $company n";
echo "ID CustomerID DATEn";
foreach($items as $item){
// items in company
echo "{$item['id']} {$item['customerid']} {$item['date']}n";
}
}
Thanks for helping but I get that error; Warning: Illegal offset type in report.php on line 54 $queryresult[$resultquery['group'] = $resultquery;
– Alper Köse
Nov 20 '18 at 4:55
You can add @ at@$queryresult[$company] = $resultquery;
to avoid this warning. It's because you are creating a new inexistent key for each group. Otherwise you can do a key check. I updated the example code.
– F.Igor
Nov 20 '18 at 5:28
The code works now I made a mistake while implementing it though it does not groups the company. It doesnt show the second query for the same company. There should be 5 record outputs which, 2 A company, 1 B, 2 C, 1 D but its like A1 B1 C1 D1
– Alper Köse
Nov 20 '18 at 6:43
I changed if (array_key_exists($company,$queryresult)) { @$queryresult[$company] = ; to if (array_key_exists($customerid,$queryresult)) { @$queryresult[$customerid] = ; and it works now. Thank you very much!
– Alper Köse
Nov 20 '18 at 7:02
add a comment |
Map your data in a key-value array with Company as key (include company in the query:
$query = "SELECT customers
.ID, customers
.customerid, customers
.date, company
FROM customers
WHERE month(DATE)= month(CURRENT_DATE()) AND YEAR(DATE) = YEAR(CURRENT_DATE())";
$query = "SELECT `customers`.ID, `customers`.customerid, `customers`.date
FROM `customers` WHERE month(DATE)= month(CURRENT_DATE()) AND YEAR(DATE) = YEAR(CURRENT_DATE());
Then simplify the data collection using a key to group items:
$result = $mysqli->query($query);
$queryresult = ;
while($resultquery = $result->fetch_array())
{
$company = $resultquery['company'];
if (array_key_exists($company,$queryresult){
@$queryresult[$company] = ;
}
@$queryresult[$company] = $resultquery;
}
An then you can present the information using foreach:
foreach($queryresult as $company => $items){
// header by company
echo "Company Name: $company n";
echo "ID CustomerID DATEn";
foreach($items as $item){
// items in company
echo "{$item['id']} {$item['customerid']} {$item['date']}n";
}
}
Thanks for helping but I get that error; Warning: Illegal offset type in report.php on line 54 $queryresult[$resultquery['group'] = $resultquery;
– Alper Köse
Nov 20 '18 at 4:55
You can add @ at@$queryresult[$company] = $resultquery;
to avoid this warning. It's because you are creating a new inexistent key for each group. Otherwise you can do a key check. I updated the example code.
– F.Igor
Nov 20 '18 at 5:28
The code works now I made a mistake while implementing it though it does not groups the company. It doesnt show the second query for the same company. There should be 5 record outputs which, 2 A company, 1 B, 2 C, 1 D but its like A1 B1 C1 D1
– Alper Köse
Nov 20 '18 at 6:43
I changed if (array_key_exists($company,$queryresult)) { @$queryresult[$company] = ; to if (array_key_exists($customerid,$queryresult)) { @$queryresult[$customerid] = ; and it works now. Thank you very much!
– Alper Köse
Nov 20 '18 at 7:02
add a comment |
Map your data in a key-value array with Company as key (include company in the query:
$query = "SELECT customers
.ID, customers
.customerid, customers
.date, company
FROM customers
WHERE month(DATE)= month(CURRENT_DATE()) AND YEAR(DATE) = YEAR(CURRENT_DATE())";
$query = "SELECT `customers`.ID, `customers`.customerid, `customers`.date
FROM `customers` WHERE month(DATE)= month(CURRENT_DATE()) AND YEAR(DATE) = YEAR(CURRENT_DATE());
Then simplify the data collection using a key to group items:
$result = $mysqli->query($query);
$queryresult = ;
while($resultquery = $result->fetch_array())
{
$company = $resultquery['company'];
if (array_key_exists($company,$queryresult){
@$queryresult[$company] = ;
}
@$queryresult[$company] = $resultquery;
}
An then you can present the information using foreach:
foreach($queryresult as $company => $items){
// header by company
echo "Company Name: $company n";
echo "ID CustomerID DATEn";
foreach($items as $item){
// items in company
echo "{$item['id']} {$item['customerid']} {$item['date']}n";
}
}
Map your data in a key-value array with Company as key (include company in the query:
$query = "SELECT customers
.ID, customers
.customerid, customers
.date, company
FROM customers
WHERE month(DATE)= month(CURRENT_DATE()) AND YEAR(DATE) = YEAR(CURRENT_DATE())";
$query = "SELECT `customers`.ID, `customers`.customerid, `customers`.date
FROM `customers` WHERE month(DATE)= month(CURRENT_DATE()) AND YEAR(DATE) = YEAR(CURRENT_DATE());
Then simplify the data collection using a key to group items:
$result = $mysqli->query($query);
$queryresult = ;
while($resultquery = $result->fetch_array())
{
$company = $resultquery['company'];
if (array_key_exists($company,$queryresult){
@$queryresult[$company] = ;
}
@$queryresult[$company] = $resultquery;
}
An then you can present the information using foreach:
foreach($queryresult as $company => $items){
// header by company
echo "Company Name: $company n";
echo "ID CustomerID DATEn";
foreach($items as $item){
// items in company
echo "{$item['id']} {$item['customerid']} {$item['date']}n";
}
}
edited Nov 20 '18 at 5:31
answered Nov 20 '18 at 4:12


F.IgorF.Igor
2,0271717
2,0271717
Thanks for helping but I get that error; Warning: Illegal offset type in report.php on line 54 $queryresult[$resultquery['group'] = $resultquery;
– Alper Köse
Nov 20 '18 at 4:55
You can add @ at@$queryresult[$company] = $resultquery;
to avoid this warning. It's because you are creating a new inexistent key for each group. Otherwise you can do a key check. I updated the example code.
– F.Igor
Nov 20 '18 at 5:28
The code works now I made a mistake while implementing it though it does not groups the company. It doesnt show the second query for the same company. There should be 5 record outputs which, 2 A company, 1 B, 2 C, 1 D but its like A1 B1 C1 D1
– Alper Köse
Nov 20 '18 at 6:43
I changed if (array_key_exists($company,$queryresult)) { @$queryresult[$company] = ; to if (array_key_exists($customerid,$queryresult)) { @$queryresult[$customerid] = ; and it works now. Thank you very much!
– Alper Köse
Nov 20 '18 at 7:02
add a comment |
Thanks for helping but I get that error; Warning: Illegal offset type in report.php on line 54 $queryresult[$resultquery['group'] = $resultquery;
– Alper Köse
Nov 20 '18 at 4:55
You can add @ at@$queryresult[$company] = $resultquery;
to avoid this warning. It's because you are creating a new inexistent key for each group. Otherwise you can do a key check. I updated the example code.
– F.Igor
Nov 20 '18 at 5:28
The code works now I made a mistake while implementing it though it does not groups the company. It doesnt show the second query for the same company. There should be 5 record outputs which, 2 A company, 1 B, 2 C, 1 D but its like A1 B1 C1 D1
– Alper Köse
Nov 20 '18 at 6:43
I changed if (array_key_exists($company,$queryresult)) { @$queryresult[$company] = ; to if (array_key_exists($customerid,$queryresult)) { @$queryresult[$customerid] = ; and it works now. Thank you very much!
– Alper Köse
Nov 20 '18 at 7:02
Thanks for helping but I get that error; Warning: Illegal offset type in report.php on line 54 $queryresult[$resultquery['group'] = $resultquery;
– Alper Köse
Nov 20 '18 at 4:55
Thanks for helping but I get that error; Warning: Illegal offset type in report.php on line 54 $queryresult[$resultquery['group'] = $resultquery;
– Alper Köse
Nov 20 '18 at 4:55
You can add @ at
@$queryresult[$company] = $resultquery;
to avoid this warning. It's because you are creating a new inexistent key for each group. Otherwise you can do a key check. I updated the example code.– F.Igor
Nov 20 '18 at 5:28
You can add @ at
@$queryresult[$company] = $resultquery;
to avoid this warning. It's because you are creating a new inexistent key for each group. Otherwise you can do a key check. I updated the example code.– F.Igor
Nov 20 '18 at 5:28
The code works now I made a mistake while implementing it though it does not groups the company. It doesnt show the second query for the same company. There should be 5 record outputs which, 2 A company, 1 B, 2 C, 1 D but its like A1 B1 C1 D1
– Alper Köse
Nov 20 '18 at 6:43
The code works now I made a mistake while implementing it though it does not groups the company. It doesnt show the second query for the same company. There should be 5 record outputs which, 2 A company, 1 B, 2 C, 1 D but its like A1 B1 C1 D1
– Alper Köse
Nov 20 '18 at 6:43
I changed if (array_key_exists($company,$queryresult)) { @$queryresult[$company] = ; to if (array_key_exists($customerid,$queryresult)) { @$queryresult[$customerid] = ; and it works now. Thank you very much!
– Alper Köse
Nov 20 '18 at 7:02
I changed if (array_key_exists($company,$queryresult)) { @$queryresult[$company] = ; to if (array_key_exists($customerid,$queryresult)) { @$queryresult[$customerid] = ; and it works now. Thank you very much!
– Alper Köse
Nov 20 '18 at 7:02
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385615%2ffetch-rows-and-check-if-has-same-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Your query contains a syntax error; a missing closing quote. Is that just a bad paste?
– Funk Forty Niner
Nov 20 '18 at 3:05
You could store the results in the array based off the
customerid
, ie$queryresult[$resultquery['customerid'] = $resultquery;
. Then you can loop over those to create your groups– Sean
Nov 20 '18 at 3:19
@FunkFortyNiner yes it is. I have closing quote in my file.
– Alper Köse
Nov 20 '18 at 3:38
@Sean can you re-write my code with an explanation please? I dont know how to loop exactly and get the data from it. Thank you
– Alper Köse
Nov 20 '18 at 3:40
I don't see any of your code past
foreach($queryresult as $queryresults) {
, so I don't how I can re-write the code. I don't see whereCompany Name: A
is coming from– Sean
Nov 20 '18 at 3:44