PDA

View Full Version : Using Switch to choose db table



ptmuldoon
03-21-2007, 02:42 AM
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?


$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'";

Inigoesdr
03-21-2007, 03:05 AM
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.