Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts

    mysql_query and switch

    Okay, so I'm making a chat for a game that I'm working on. And well, I'm having a little problem. So what I'm trying to do is if the user_level is 4 the user is a GM if the user_level is 3 the user is a mod.

    The problem is that whenever I do this switch statement it seems to be ignoring the user_level. The only result that I seem to get out of this script is

    ~GM~ Username: and the message

    PHP Code:
    <?php
    include("/var/www/connect.php");

    $chat mysql_query("SELECT * FROM chat ORDER BY msg_id limit 50");
    $msg mysql_fetch_array($chat);
       
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml" > 
    <head>
    <style type="text/css">
    body {
    background-color:#000000;
    margin:0px;
    color:#ffffff;
    }
    </style>
    </head>
       <body>
       
     <table align="center" cellpadding="0" cellspacing="0"> 
     <?php  
    switch($msg['user_level']) {

       case 
    3:

    while(
    $msg mysql_fetch_array($chat)) {

      echo 
    "<tr>";
      echo 
    "<td align=\"left\" valign=\"middle\">~MOD~" $msg['username'] . ": " $msg['msg'] . "</tr>";
      echo 
    "</tr>";

       }

      break;
      
      case 
    4:
      
      
      while(
    $msg mysql_fetch_array($chat)) {
      
      echo 
    "<tr>";
      echo 
    "<td align=\"left\" valign=\"middle\">~GM~" $msg['username'] . ": " $msg['msg'] . "</td>";
      echo 
    "</tr>";

      }

      break;
     
      default:
      
     while(
    $msg mysql_fetch_array($chat)) {
      
      echo 
    "<tr>";
      echo 
    "<td align=\"left\" valign=\"left\">"$msg['username'] . ": " $msg['msg'] . "</td>";
      echo 
    "</tr>";

      break;
     
       }


    ?>
    </table>
       </body>
    </html>
    So the whole goal is to show their rank. How it works... Or well, it is suppose to work is the user submits their message, along with that message it also gets the user_id that the user is logged in with. Then when it come to the page to show on the screen I want it to sort through the data and if the user_level is 4

    ~GM~username: And the message

    if the user level is 3

    ~MOD~username: and the message

    and if its a normal user then

    Username: And the message.



    Thanks for the help.

    Jon W

  • #2
    New Coder
    Join Date
    Mar 2009
    Location
    Chicago, IL
    Posts
    69
    Thanks
    0
    Thanked 15 Times in 15 Posts
    Try this:

    PHP Code:
    <table align="center" cellpadding="0" cellspacing="0"> 
    <?php
    $query 
    mysql_query("SELECT * FROM chat ORDER BY msg_id limit 50");

    while (
    $row mysql_fetch_array($queryMYSQL_ASSOC))
    {
        switch(
    $row['user_level']):
            case 
    3:
                
    $user_level '~MOD~';
            break;
            case 
    4:
                
    $user_level '~GM~';
            break;
            default:
                
    $user_level '';
            break;
        endswitch;
        
        echo 
    "<tr>";
        echo 
    "<td align=\"left\" valign=\"middle\">{$user_level} {$row['username']}: {$row['msg']}</tr>";
        echo 
    "</tr>";
        
    }  
    ?>
    </table>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •