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.










share|improve this question




























    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.










    share|improve this question


























      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.










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 8 at 22:23









      Nisarg

      1,34131123




      1,34131123










      asked Nov 5 at 21:03









      myster dee

      11




      11
























          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.






          share|improve this answer





















          • ok thank you for your input...
            – myster dee
            Nov 5 at 21:15











          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',
          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%2f53162175%2fsort-and-separate-names-from-a-database%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








          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.






          share|improve this answer





















          • ok thank you for your input...
            – myster dee
            Nov 5 at 21:15















          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.






          share|improve this answer





















          • ok thank you for your input...
            – myster dee
            Nov 5 at 21:15













          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 5 at 21:12









          msturek

          491514




          491514












          • 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




          ok thank you for your input...
          – myster dee
          Nov 5 at 21:15


















          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.





          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.




          draft saved


          draft discarded














          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





















































          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







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()