populating a dropdown menu based on user login

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • goresus
    New Member
    • Nov 2006
    • 10

    populating a dropdown menu based on user login

    Hello there,

    I am trying to populate one of my drop-down menus with the names of the people who are currently logged in. In addition, I want the names to be removed from the list if they choose to log out.

    Here is what I have so far: I have the log in/out script working. so after the user logs in, his/her name is recorded in a variable.

    My question: how do I add this name to the drop-down menu every time someone logs in?

    if it helps at all this is the bit of code i have so far:
    [php]<td width = "50"><selec t name="loggedWai ters" value = "your name">
    $key = 0;
    <?php
    //echo <option value="">your name</option>
    echo '<option value="'. $key+1 . '">' .$empName. '</option>';


    ?>
    </select></td>[/php]
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    When a user logs in, you can record this in the database. When a user logs off ditto.
    So you can build a dropdown list of every user logged in dynamically from the db and display this list at the screen. But it will of course only be updated on the user's screen when the current page is reloaded or a new page loaded.

    Ronald :cool:

    Comment

    • goresus
      New Member
      • Nov 2006
      • 10

      #3
      Originally posted by ronverdonk
      When a user logs in, you can record this in the database. When a user logs off ditto.
      So you can build a dropdown list of every user logged in dynamically from the db and display this list at the screen. But it will of course only be updated on the user's screen when the current page is reloaded or a new page loaded.

      Ronald :cool:
      Hi Ronald thanks a lot for your reply. I am thinking, rather than a database, what if i create an array of people logged in and then go from there. I tried to implement this but I think my codes arent working.

      I added a few lines of codes. But still the dropdown menu is not showing multiple users who are logged in. it only shows the last user. let me know if you have any idea about what is going wrong.


      [php]<td width = "50"><selec t name="loggedWai ters" value = "your name">
      $key = 0;
      <?php

      $loggedWaiters = array("your name");
      if($numRows) $loggedWaiters = array($loggedWa iters, $empName);
      $key +1;
      //echo <option value="">your name</option>
      foreach($logged Waiters as $val)
      echo '<option value="' . $key . '">' . $val . '</option>';


      ?>
      </select></td>[/php]

      Comment

      • goresus
        New Member
        • Nov 2006
        • 10

        #4
        i see why an array wont work in this case. i will now try the temporary database idea. thanks!

        Comment

        • goresus
          New Member
          • Nov 2006
          • 10

          #5
          Hello there,

          I am trying to populate my drop-down menu from a temporary table named LoggedWaiterNam e. This table has only one feild that contains user ids of the logged users.

          I am facing a major problem looping down the column. How do I go to the next row in the table, so that I can add the next value in the column to the menu? Please help.

          I have included the codes that I have so far. Thanks a lot in advance.

          [php]<?php
          $loggedWaiterTa ble_sql = "SELECT * FROM LoggedWaiterNam e";
          $loggedWaiterTa ble_result = mysql_query($lo ggedWaiterTable _sql, $db);
          $loggedWaiterTa ble_numRows = mysql_num_rows( $loggedWaiterTa ble_result);

          for ( $counter = 1; $counter <= $loggedWaiterTa ble_numRows; $counter += 1) {

          echo ' <option value="$counter ">' . $waiterName . '</option>' . "\n";
          }

          ?>[/php]

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            Something like this. I shorted the variable names for clarity:
            Code:
            <?php
            // here is your db server logon 
            // and db selection
            $sql = "SELECT * FROM LoggedWaiterName"; 
            $result = mysql_query($sql) 
               or die("Invalid select: ".mysql_error());
            $counter = 1;
            echo "<select name="selbox"> 
            while ($row = mysql_fetch_assoc($result)) {
               echo " <option value='$counter'>" . $row['waiterName'] . "</option>\n";
               $counter++;
            }
            echo "</select>";
            ?>
            Ronald :cool:

            Comment

            • goresus
              New Member
              • Nov 2006
              • 10

              #7
              Ronald, that was very helpful. My code finally works. I will look into how it actually dowes that. Thanks a lot for saving my day!

              G

              Comment

              Working...