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 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    help with a form

    Hi, im having an issue with a form im working on. Its for a server owner, on the server are four games, each with its own Admin. The form is going to let the server owner assign an Admin to a specific game. In the form, I have 3 columns, 1) the game name 2) the current admin 3) a list of all potential admins. When the form is submitted, it updates all the game admins to the selected admin in the third column.

    Here is the code for this:

    PHP Code:
    $gamequery="SELECT game_id, name, admin_name, admin_id FROM se_games WHERE game_id !=0 ORDER BY game_id ASC"
    $gameresult=mysql_query($gamequery); 

    while (
    $row mysql_fetch_assoc($gameresult)) { 
        
    echo 
    "<tr><td>$row[name]</td><td>$row[admin_name]</td><td><select name=\"_admin\">";
    db(__FILE__,__LINE__,"SELECT login_id, login_name FROM user_accounts WHERE powers != 3 ORDER BY login_id ASC");
            
    while(
    $dest dbr()) {

    echo 
    "<option value=$dest[login_id]> $dest[login_name]";
                
    }
    echo 
    "</select></td></tr>";
            

    What I would like, is that in the 3rd column, the Admins are listed alphabetically, but the current Admin will always be the 1st option. I had a little play with it myself, but couldn't get it working as I'd like. Any help would be great

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    What's the relationship here between se_games and user_accounts? Is it one to many or many to many? And does login_id correspond to the admin_id?
    I'm thinking a union may work well for this.

  • #3
    New Coder
    Join Date
    Feb 2009
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    they arent related by a primary key but yes login_id = admin_id and login_name = admin_name
    Last edited by tim_poole247; 11-21-2012 at 08:16 PM.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    So only one user can administer one game at a time? Alright, that should be okay for this.
    To force the existing owner first, I'd suggest the easiest solution is to try a union:
    Code:
    (SELECT u.login_id, u.login_name FROM user_accounts u INNER JOIN se_games g ON g.admin_id = u.login_id WHERE g.game_id = $row['game_id'])
    UNION
    (SELECT login_id, login_name FROM user_accounts WHERE powers != 3 AND login_id <> $row['admin_id'] ORDER BY login_id ASC)
    I believe that will stack it and not sort the external union. $row['game_id'] will be for the existing game in this iteration of the exterior query. I'm sure it would be complicated, but you could also fetch all the games at the same time with the possible users and existing administrators (easy task without the force of the existing at the top of the list though).

    Try running that up in a client and give it an explicit game_id to see if it works properly.

  • Users who have thanked Fou-Lu for this post:

    tim_poole247 (11-21-2012)

  • #5
    New Coder
    Join Date
    Feb 2009
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    lovely job mate ta very much


  •  

    Posting Permissions

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