Count the duplicate rows of a table and continue the calculation
I have the following table in mysql database
database name = roulette
id | number | user
1 | 18 | John
2 | 14 | Administrator
3 | 14 | Administrator
4 | 19 | Administrator
5 | 17 | Administrator
Now I would like to continue in the following condition:
The System must only take into account the numbers of the "Administrator" user and continue the calculation if there is at least one duplicate.
So in my example we have the number 14 repeating at least 2 times and we will have to proceed.
I do not know how to get this number from the query. I tried the following code but it does not work:
$connectiondb = mysqli_connect($servername, $username, $password, $dbname);
$duplicates = mysqli_query($connectiondb, "SELECT number, COUNT(*) as count
FROM roulette
GROUP BY number
HAVING COUNT(*) > 0");
if(mysqli_num_rows($duplicates) > 0){
echo "There is at least one duplicate number for the selected user. We proceed.";
}
Plus with this query I also get the error:
PHP Recoverable fatal error: Object of class mysqli_result could not
be converted to string
php mysqli
add a comment |
I have the following table in mysql database
database name = roulette
id | number | user
1 | 18 | John
2 | 14 | Administrator
3 | 14 | Administrator
4 | 19 | Administrator
5 | 17 | Administrator
Now I would like to continue in the following condition:
The System must only take into account the numbers of the "Administrator" user and continue the calculation if there is at least one duplicate.
So in my example we have the number 14 repeating at least 2 times and we will have to proceed.
I do not know how to get this number from the query. I tried the following code but it does not work:
$connectiondb = mysqli_connect($servername, $username, $password, $dbname);
$duplicates = mysqli_query($connectiondb, "SELECT number, COUNT(*) as count
FROM roulette
GROUP BY number
HAVING COUNT(*) > 0");
if(mysqli_num_rows($duplicates) > 0){
echo "There is at least one duplicate number for the selected user. We proceed.";
}
Plus with this query I also get the error:
PHP Recoverable fatal error: Object of class mysqli_result could not
be converted to string
php mysqli
add a comment |
I have the following table in mysql database
database name = roulette
id | number | user
1 | 18 | John
2 | 14 | Administrator
3 | 14 | Administrator
4 | 19 | Administrator
5 | 17 | Administrator
Now I would like to continue in the following condition:
The System must only take into account the numbers of the "Administrator" user and continue the calculation if there is at least one duplicate.
So in my example we have the number 14 repeating at least 2 times and we will have to proceed.
I do not know how to get this number from the query. I tried the following code but it does not work:
$connectiondb = mysqli_connect($servername, $username, $password, $dbname);
$duplicates = mysqli_query($connectiondb, "SELECT number, COUNT(*) as count
FROM roulette
GROUP BY number
HAVING COUNT(*) > 0");
if(mysqli_num_rows($duplicates) > 0){
echo "There is at least one duplicate number for the selected user. We proceed.";
}
Plus with this query I also get the error:
PHP Recoverable fatal error: Object of class mysqli_result could not
be converted to string
php mysqli
I have the following table in mysql database
database name = roulette
id | number | user
1 | 18 | John
2 | 14 | Administrator
3 | 14 | Administrator
4 | 19 | Administrator
5 | 17 | Administrator
Now I would like to continue in the following condition:
The System must only take into account the numbers of the "Administrator" user and continue the calculation if there is at least one duplicate.
So in my example we have the number 14 repeating at least 2 times and we will have to proceed.
I do not know how to get this number from the query. I tried the following code but it does not work:
$connectiondb = mysqli_connect($servername, $username, $password, $dbname);
$duplicates = mysqli_query($connectiondb, "SELECT number, COUNT(*) as count
FROM roulette
GROUP BY number
HAVING COUNT(*) > 0");
if(mysqli_num_rows($duplicates) > 0){
echo "There is at least one duplicate number for the selected user. We proceed.";
}
Plus with this query I also get the error:
PHP Recoverable fatal error: Object of class mysqli_result could not
be converted to string
php mysqli
php mysqli
edited Jan 3 at 8:33
Miraj50
2,78011025
2,78011025
asked Jan 3 at 0:09
VitoVito
11
11
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
try using count(*) in your query and the following command to access your result set:
while ($row = $result->fetch_assoc()) {
echo $row['classtype']."<br>";
}
mysqli_query returns an object resource to your variable, not a string.
refer: Object of class mysqli_result could not be converted to string in
add a comment |
Problem solved. If the following numbers are present in the column:
13
13
14
14
15
the numbers 13 and 14 are repeated at least twice.
$duplicate = mysqli_query($connectiondb, "SELECT id, COUNT(number) FROM roulette WHERE user = '$user' GROUP BY number HAVING COUNT(number) > 1");
echo "Duplicate in this table: ".mysqli_num_rows($duplicate)."<br>";
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%2f54014805%2fcount-the-duplicate-rows-of-a-table-and-continue-the-calculation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
try using count(*) in your query and the following command to access your result set:
while ($row = $result->fetch_assoc()) {
echo $row['classtype']."<br>";
}
mysqli_query returns an object resource to your variable, not a string.
refer: Object of class mysqli_result could not be converted to string in
add a comment |
try using count(*) in your query and the following command to access your result set:
while ($row = $result->fetch_assoc()) {
echo $row['classtype']."<br>";
}
mysqli_query returns an object resource to your variable, not a string.
refer: Object of class mysqli_result could not be converted to string in
add a comment |
try using count(*) in your query and the following command to access your result set:
while ($row = $result->fetch_assoc()) {
echo $row['classtype']."<br>";
}
mysqli_query returns an object resource to your variable, not a string.
refer: Object of class mysqli_result could not be converted to string in
try using count(*) in your query and the following command to access your result set:
while ($row = $result->fetch_assoc()) {
echo $row['classtype']."<br>";
}
mysqli_query returns an object resource to your variable, not a string.
refer: Object of class mysqli_result could not be converted to string in
answered Jan 3 at 0:24
DjokerSDjokerS
5410
5410
add a comment |
add a comment |
Problem solved. If the following numbers are present in the column:
13
13
14
14
15
the numbers 13 and 14 are repeated at least twice.
$duplicate = mysqli_query($connectiondb, "SELECT id, COUNT(number) FROM roulette WHERE user = '$user' GROUP BY number HAVING COUNT(number) > 1");
echo "Duplicate in this table: ".mysqli_num_rows($duplicate)."<br>";
add a comment |
Problem solved. If the following numbers are present in the column:
13
13
14
14
15
the numbers 13 and 14 are repeated at least twice.
$duplicate = mysqli_query($connectiondb, "SELECT id, COUNT(number) FROM roulette WHERE user = '$user' GROUP BY number HAVING COUNT(number) > 1");
echo "Duplicate in this table: ".mysqli_num_rows($duplicate)."<br>";
add a comment |
Problem solved. If the following numbers are present in the column:
13
13
14
14
15
the numbers 13 and 14 are repeated at least twice.
$duplicate = mysqli_query($connectiondb, "SELECT id, COUNT(number) FROM roulette WHERE user = '$user' GROUP BY number HAVING COUNT(number) > 1");
echo "Duplicate in this table: ".mysqli_num_rows($duplicate)."<br>";
Problem solved. If the following numbers are present in the column:
13
13
14
14
15
the numbers 13 and 14 are repeated at least twice.
$duplicate = mysqli_query($connectiondb, "SELECT id, COUNT(number) FROM roulette WHERE user = '$user' GROUP BY number HAVING COUNT(number) > 1");
echo "Duplicate in this table: ".mysqli_num_rows($duplicate)."<br>";
answered Jan 3 at 1:05
VitoVito
11
11
add a comment |
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%2f54014805%2fcount-the-duplicate-rows-of-a-table-and-continue-the-calculation%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