Sort and separate names from a database
up vote
0
down vote
favorite
Could anybody point me in the right direction?
I have a database with a handful of messages. Each message has a username also..
I wish to use the names of the messages in a drop down menu so that the user can click a user and view the messages from the user.
THE PROBLEM: the drop down list shows every user of every message and i don-not know how to separate the users so that if there is 7 messages from ROB only 1 ROB will be shown in the drop down list..
I hope I am making sense here.
So if anyone could help me here, I would be grateful.
What sort of query should I be using the separate every user from the database so I can show them in the drop-down menu, as individual users...
Instead of the same user being shown for as many messages as the user wrote.
Below is the current query..
<div class='userbox'>
<header class='ubheader'>Contacts</header>
<section class='ubmain'>
";
$db = new PDO("mysql:host=localhost;dbname=messages", 'root', ''); // 1. set database with this instead of conect - or change conect to this
$query="SELECT * FROM `messagedatabase` WHERE `listID`='$listID' ORDER BY messagedate DESC";
$stat=$db->prepare($query);
$stat->execute();
$Mcount = $stat->rowCount();
$messagecount=$Mcount;
while($row = $stat->fetch()){
$messageaccountname=$row['messageaccountname'];
if ($messageaccountname != $useraccountname){
echo"<div class='ubnames' onclick='selectmessage("{$messageaccountname}")'>{$messageaccountname}</div>";
}
}
echo "
</section>
</div>
";
Any help would be appreciated.
Many thanks.
javascript sql database
add a comment |
up vote
0
down vote
favorite
Could anybody point me in the right direction?
I have a database with a handful of messages. Each message has a username also..
I wish to use the names of the messages in a drop down menu so that the user can click a user and view the messages from the user.
THE PROBLEM: the drop down list shows every user of every message and i don-not know how to separate the users so that if there is 7 messages from ROB only 1 ROB will be shown in the drop down list..
I hope I am making sense here.
So if anyone could help me here, I would be grateful.
What sort of query should I be using the separate every user from the database so I can show them in the drop-down menu, as individual users...
Instead of the same user being shown for as many messages as the user wrote.
Below is the current query..
<div class='userbox'>
<header class='ubheader'>Contacts</header>
<section class='ubmain'>
";
$db = new PDO("mysql:host=localhost;dbname=messages", 'root', ''); // 1. set database with this instead of conect - or change conect to this
$query="SELECT * FROM `messagedatabase` WHERE `listID`='$listID' ORDER BY messagedate DESC";
$stat=$db->prepare($query);
$stat->execute();
$Mcount = $stat->rowCount();
$messagecount=$Mcount;
while($row = $stat->fetch()){
$messageaccountname=$row['messageaccountname'];
if ($messageaccountname != $useraccountname){
echo"<div class='ubnames' onclick='selectmessage("{$messageaccountname}")'>{$messageaccountname}</div>";
}
}
echo "
</section>
</div>
";
Any help would be appreciated.
Many thanks.
javascript sql database
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Could anybody point me in the right direction?
I have a database with a handful of messages. Each message has a username also..
I wish to use the names of the messages in a drop down menu so that the user can click a user and view the messages from the user.
THE PROBLEM: the drop down list shows every user of every message and i don-not know how to separate the users so that if there is 7 messages from ROB only 1 ROB will be shown in the drop down list..
I hope I am making sense here.
So if anyone could help me here, I would be grateful.
What sort of query should I be using the separate every user from the database so I can show them in the drop-down menu, as individual users...
Instead of the same user being shown for as many messages as the user wrote.
Below is the current query..
<div class='userbox'>
<header class='ubheader'>Contacts</header>
<section class='ubmain'>
";
$db = new PDO("mysql:host=localhost;dbname=messages", 'root', ''); // 1. set database with this instead of conect - or change conect to this
$query="SELECT * FROM `messagedatabase` WHERE `listID`='$listID' ORDER BY messagedate DESC";
$stat=$db->prepare($query);
$stat->execute();
$Mcount = $stat->rowCount();
$messagecount=$Mcount;
while($row = $stat->fetch()){
$messageaccountname=$row['messageaccountname'];
if ($messageaccountname != $useraccountname){
echo"<div class='ubnames' onclick='selectmessage("{$messageaccountname}")'>{$messageaccountname}</div>";
}
}
echo "
</section>
</div>
";
Any help would be appreciated.
Many thanks.
javascript sql database
Could anybody point me in the right direction?
I have a database with a handful of messages. Each message has a username also..
I wish to use the names of the messages in a drop down menu so that the user can click a user and view the messages from the user.
THE PROBLEM: the drop down list shows every user of every message and i don-not know how to separate the users so that if there is 7 messages from ROB only 1 ROB will be shown in the drop down list..
I hope I am making sense here.
So if anyone could help me here, I would be grateful.
What sort of query should I be using the separate every user from the database so I can show them in the drop-down menu, as individual users...
Instead of the same user being shown for as many messages as the user wrote.
Below is the current query..
<div class='userbox'>
<header class='ubheader'>Contacts</header>
<section class='ubmain'>
";
$db = new PDO("mysql:host=localhost;dbname=messages", 'root', ''); // 1. set database with this instead of conect - or change conect to this
$query="SELECT * FROM `messagedatabase` WHERE `listID`='$listID' ORDER BY messagedate DESC";
$stat=$db->prepare($query);
$stat->execute();
$Mcount = $stat->rowCount();
$messagecount=$Mcount;
while($row = $stat->fetch()){
$messageaccountname=$row['messageaccountname'];
if ($messageaccountname != $useraccountname){
echo"<div class='ubnames' onclick='selectmessage("{$messageaccountname}")'>{$messageaccountname}</div>";
}
}
echo "
</section>
</div>
";
Any help would be appreciated.
Many thanks.
javascript sql database
javascript sql database
edited Nov 8 at 22:23
Nisarg
1,34131123
1,34131123
asked Nov 5 at 21:03
myster dee
11
11
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
The simple solution would be to add a DISTINCT clause to your query, such as:
SELECT DISTINCT messageaccountname FROM ....
Beyond that, it sounds like the database isn't normalized. Ideally, you'd have your accounts in a separate table that would be related to your messagedatabase
table. But database design is a different discussion beyond the scope of this post.
ok thank you for your input...
– myster dee
Nov 5 at 21:15
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
The simple solution would be to add a DISTINCT clause to your query, such as:
SELECT DISTINCT messageaccountname FROM ....
Beyond that, it sounds like the database isn't normalized. Ideally, you'd have your accounts in a separate table that would be related to your messagedatabase
table. But database design is a different discussion beyond the scope of this post.
ok thank you for your input...
– myster dee
Nov 5 at 21:15
add a comment |
up vote
1
down vote
The simple solution would be to add a DISTINCT clause to your query, such as:
SELECT DISTINCT messageaccountname FROM ....
Beyond that, it sounds like the database isn't normalized. Ideally, you'd have your accounts in a separate table that would be related to your messagedatabase
table. But database design is a different discussion beyond the scope of this post.
ok thank you for your input...
– myster dee
Nov 5 at 21:15
add a comment |
up vote
1
down vote
up vote
1
down vote
The simple solution would be to add a DISTINCT clause to your query, such as:
SELECT DISTINCT messageaccountname FROM ....
Beyond that, it sounds like the database isn't normalized. Ideally, you'd have your accounts in a separate table that would be related to your messagedatabase
table. But database design is a different discussion beyond the scope of this post.
The simple solution would be to add a DISTINCT clause to your query, such as:
SELECT DISTINCT messageaccountname FROM ....
Beyond that, it sounds like the database isn't normalized. Ideally, you'd have your accounts in a separate table that would be related to your messagedatabase
table. But database design is a different discussion beyond the scope of this post.
answered Nov 5 at 21:12
msturek
491514
491514
ok thank you for your input...
– myster dee
Nov 5 at 21:15
add a comment |
ok thank you for your input...
– myster dee
Nov 5 at 21:15
ok thank you for your input...
– myster dee
Nov 5 at 21:15
ok thank you for your input...
– myster dee
Nov 5 at 21:15
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53162175%2fsort-and-separate-names-from-a-database%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