mysql database for messages Query for pulling number of unread messages(with query)
up vote
0
down vote
favorite
i have a database for messages and i am currently able to pull the amount of messages an individual user has sent and the user names with the DISTINCT count(*) query, But i am un able to now pull the messages that have a notread column. my question is from the query below can anybody see a quik fix to display the number of unread messages . my database has a READ coloumn with either yes or no input at message creation..
The below query pulls the user names and the amount of messages from each user and displays the username and messages amount number by the side..
I wish to however replace the amount of messages with amount of messages unread.
here is the code
$db = new PDO("mysql:host=localhost;dbname=messages", 'root', ''); // 1. set database with this instead of conect - or change conect to this
$query="SELECT DISTINCT messageaccountname,count(*) FROM `messagedatabase` WHERE `listID`='$listID' GROUP BY messageaccountname ";
$stat=$db->prepare($query);
$stat->execute();
while($row = $stat->fetch()){
$messagenumber = $row['count(*)'];
$messageaccountname=$row['messageaccountname'];
if ($messageaccountname != $useraccountname){
echo"<div id='namecon' class='ubnames' onclick='selectmessage("{$messageaccountname}")'>{$messageaccountname} ({$messagenumber}) </div>";
}
}
im thinking i need to change the messageaccountname,count(*) WHERE listID=$listID GROUP BY messageaccountname
but i am unsure as to how i should then display the number of results,
if anyone can see what i need to do please let me know, as i have been looking all day for the answer and have not found it yet.
Thank you all.
Lez
php html mysql
add a comment |
up vote
0
down vote
favorite
i have a database for messages and i am currently able to pull the amount of messages an individual user has sent and the user names with the DISTINCT count(*) query, But i am un able to now pull the messages that have a notread column. my question is from the query below can anybody see a quik fix to display the number of unread messages . my database has a READ coloumn with either yes or no input at message creation..
The below query pulls the user names and the amount of messages from each user and displays the username and messages amount number by the side..
I wish to however replace the amount of messages with amount of messages unread.
here is the code
$db = new PDO("mysql:host=localhost;dbname=messages", 'root', ''); // 1. set database with this instead of conect - or change conect to this
$query="SELECT DISTINCT messageaccountname,count(*) FROM `messagedatabase` WHERE `listID`='$listID' GROUP BY messageaccountname ";
$stat=$db->prepare($query);
$stat->execute();
while($row = $stat->fetch()){
$messagenumber = $row['count(*)'];
$messageaccountname=$row['messageaccountname'];
if ($messageaccountname != $useraccountname){
echo"<div id='namecon' class='ubnames' onclick='selectmessage("{$messageaccountname}")'>{$messageaccountname} ({$messagenumber}) </div>";
}
}
im thinking i need to change the messageaccountname,count(*) WHERE listID=$listID GROUP BY messageaccountname
but i am unsure as to how i should then display the number of results,
if anyone can see what i need to do please let me know, as i have been looking all day for the answer and have not found it yet.
Thank you all.
Lez
php html mysql
Rarely (almost nil) we are needed to use bothDistinct
andGroup By
together.
– Madhur Bhaiya
Nov 7 at 19:44
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
i have a database for messages and i am currently able to pull the amount of messages an individual user has sent and the user names with the DISTINCT count(*) query, But i am un able to now pull the messages that have a notread column. my question is from the query below can anybody see a quik fix to display the number of unread messages . my database has a READ coloumn with either yes or no input at message creation..
The below query pulls the user names and the amount of messages from each user and displays the username and messages amount number by the side..
I wish to however replace the amount of messages with amount of messages unread.
here is the code
$db = new PDO("mysql:host=localhost;dbname=messages", 'root', ''); // 1. set database with this instead of conect - or change conect to this
$query="SELECT DISTINCT messageaccountname,count(*) FROM `messagedatabase` WHERE `listID`='$listID' GROUP BY messageaccountname ";
$stat=$db->prepare($query);
$stat->execute();
while($row = $stat->fetch()){
$messagenumber = $row['count(*)'];
$messageaccountname=$row['messageaccountname'];
if ($messageaccountname != $useraccountname){
echo"<div id='namecon' class='ubnames' onclick='selectmessage("{$messageaccountname}")'>{$messageaccountname} ({$messagenumber}) </div>";
}
}
im thinking i need to change the messageaccountname,count(*) WHERE listID=$listID GROUP BY messageaccountname
but i am unsure as to how i should then display the number of results,
if anyone can see what i need to do please let me know, as i have been looking all day for the answer and have not found it yet.
Thank you all.
Lez
php html mysql
i have a database for messages and i am currently able to pull the amount of messages an individual user has sent and the user names with the DISTINCT count(*) query, But i am un able to now pull the messages that have a notread column. my question is from the query below can anybody see a quik fix to display the number of unread messages . my database has a READ coloumn with either yes or no input at message creation..
The below query pulls the user names and the amount of messages from each user and displays the username and messages amount number by the side..
I wish to however replace the amount of messages with amount of messages unread.
here is the code
$db = new PDO("mysql:host=localhost;dbname=messages", 'root', ''); // 1. set database with this instead of conect - or change conect to this
$query="SELECT DISTINCT messageaccountname,count(*) FROM `messagedatabase` WHERE `listID`='$listID' GROUP BY messageaccountname ";
$stat=$db->prepare($query);
$stat->execute();
while($row = $stat->fetch()){
$messagenumber = $row['count(*)'];
$messageaccountname=$row['messageaccountname'];
if ($messageaccountname != $useraccountname){
echo"<div id='namecon' class='ubnames' onclick='selectmessage("{$messageaccountname}")'>{$messageaccountname} ({$messagenumber}) </div>";
}
}
im thinking i need to change the messageaccountname,count(*) WHERE listID=$listID GROUP BY messageaccountname
but i am unsure as to how i should then display the number of results,
if anyone can see what i need to do please let me know, as i have been looking all day for the answer and have not found it yet.
Thank you all.
Lez
php html mysql
php html mysql
asked Nov 7 at 13:46
lezz
205
205
Rarely (almost nil) we are needed to use bothDistinct
andGroup By
together.
– Madhur Bhaiya
Nov 7 at 19:44
add a comment |
Rarely (almost nil) we are needed to use bothDistinct
andGroup By
together.
– Madhur Bhaiya
Nov 7 at 19:44
Rarely (almost nil) we are needed to use both
Distinct
and Group By
together.– Madhur Bhaiya
Nov 7 at 19:44
Rarely (almost nil) we are needed to use both
Distinct
and Group By
together.– Madhur Bhaiya
Nov 7 at 19:44
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
i accept your READ column type is varchar or enum with values YES and NO. so if you change your query like below you can get the unreaded messages count
SELECT DISTINCT messageaccountname,count(*), sum(if(read = "NO", 1, 0)) unread_count FROM `messagedatabase` WHERE `listID`='$listID' GROUP BY messageaccountname
hope will help you
thank you, i will try this,(unfortnatly i get blank results)
– lezz
Nov 7 at 14:18
I only wish to change $messagenumber = $row['count(*)']; to display a number of unread messages
– lezz
Nov 7 at 14:23
Also note thatDISTINCT
has no useful meaning here. AGROUP BY
query will return exactly one row per group.
– Mike Robinson
Nov 7 at 14:35
ok thank you. il ammend my query. thanks
– lezz
Nov 7 at 15:10
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
i accept your READ column type is varchar or enum with values YES and NO. so if you change your query like below you can get the unreaded messages count
SELECT DISTINCT messageaccountname,count(*), sum(if(read = "NO", 1, 0)) unread_count FROM `messagedatabase` WHERE `listID`='$listID' GROUP BY messageaccountname
hope will help you
thank you, i will try this,(unfortnatly i get blank results)
– lezz
Nov 7 at 14:18
I only wish to change $messagenumber = $row['count(*)']; to display a number of unread messages
– lezz
Nov 7 at 14:23
Also note thatDISTINCT
has no useful meaning here. AGROUP BY
query will return exactly one row per group.
– Mike Robinson
Nov 7 at 14:35
ok thank you. il ammend my query. thanks
– lezz
Nov 7 at 15:10
add a comment |
up vote
0
down vote
i accept your READ column type is varchar or enum with values YES and NO. so if you change your query like below you can get the unreaded messages count
SELECT DISTINCT messageaccountname,count(*), sum(if(read = "NO", 1, 0)) unread_count FROM `messagedatabase` WHERE `listID`='$listID' GROUP BY messageaccountname
hope will help you
thank you, i will try this,(unfortnatly i get blank results)
– lezz
Nov 7 at 14:18
I only wish to change $messagenumber = $row['count(*)']; to display a number of unread messages
– lezz
Nov 7 at 14:23
Also note thatDISTINCT
has no useful meaning here. AGROUP BY
query will return exactly one row per group.
– Mike Robinson
Nov 7 at 14:35
ok thank you. il ammend my query. thanks
– lezz
Nov 7 at 15:10
add a comment |
up vote
0
down vote
up vote
0
down vote
i accept your READ column type is varchar or enum with values YES and NO. so if you change your query like below you can get the unreaded messages count
SELECT DISTINCT messageaccountname,count(*), sum(if(read = "NO", 1, 0)) unread_count FROM `messagedatabase` WHERE `listID`='$listID' GROUP BY messageaccountname
hope will help you
i accept your READ column type is varchar or enum with values YES and NO. so if you change your query like below you can get the unreaded messages count
SELECT DISTINCT messageaccountname,count(*), sum(if(read = "NO", 1, 0)) unread_count FROM `messagedatabase` WHERE `listID`='$listID' GROUP BY messageaccountname
hope will help you
answered Nov 7 at 14:16
ilazmi
61
61
thank you, i will try this,(unfortnatly i get blank results)
– lezz
Nov 7 at 14:18
I only wish to change $messagenumber = $row['count(*)']; to display a number of unread messages
– lezz
Nov 7 at 14:23
Also note thatDISTINCT
has no useful meaning here. AGROUP BY
query will return exactly one row per group.
– Mike Robinson
Nov 7 at 14:35
ok thank you. il ammend my query. thanks
– lezz
Nov 7 at 15:10
add a comment |
thank you, i will try this,(unfortnatly i get blank results)
– lezz
Nov 7 at 14:18
I only wish to change $messagenumber = $row['count(*)']; to display a number of unread messages
– lezz
Nov 7 at 14:23
Also note thatDISTINCT
has no useful meaning here. AGROUP BY
query will return exactly one row per group.
– Mike Robinson
Nov 7 at 14:35
ok thank you. il ammend my query. thanks
– lezz
Nov 7 at 15:10
thank you, i will try this,(unfortnatly i get blank results)
– lezz
Nov 7 at 14:18
thank you, i will try this,(unfortnatly i get blank results)
– lezz
Nov 7 at 14:18
I only wish to change $messagenumber = $row['count(*)']; to display a number of unread messages
– lezz
Nov 7 at 14:23
I only wish to change $messagenumber = $row['count(*)']; to display a number of unread messages
– lezz
Nov 7 at 14:23
Also note that
DISTINCT
has no useful meaning here. A GROUP BY
query will return exactly one row per group.– Mike Robinson
Nov 7 at 14:35
Also note that
DISTINCT
has no useful meaning here. A GROUP BY
query will return exactly one row per group.– Mike Robinson
Nov 7 at 14:35
ok thank you. il ammend my query. thanks
– lezz
Nov 7 at 15:10
ok thank you. il ammend my query. thanks
– lezz
Nov 7 at 15:10
add a comment |
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%2f53190739%2fmysql-database-for-messages-query-for-pulling-number-of-unread-messageswith-que%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
Rarely (almost nil) we are needed to use both
Distinct
andGroup By
together.– Madhur Bhaiya
Nov 7 at 19:44