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
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts

    Using Switch to choose db table

    Has anyone every used a switch to decide which table a query should use?

    I'm experimenting a little, and I think the following should correct?

    PHP Code:
    $sql 'SELECT * FROM games';    
    $gamedata mysql_query($sql);
    $row mysql_fetch_assoc($gamedata);
    $game_type $row["type"];

    switch(
    $game_type){
        case 
    'R1'$table 'table1';
        break;
        case 
    'R2'$table 'table2';
        break;
        case 
    'R3'$table 'table3';
        break;
    }

    $sql "SELECT adjacencies FROM $table WHERE id = '$from_country'"

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    It would probably be easier to used an associative array of the tables, but to answer your question, yes I've seen it done before.


  •  

    Posting Permissions

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