egturnkey Posted October 3, 2009 Share Posted October 3, 2009 Hello friends, I have a problem which as follow - if we do create 4 database tables says en_m1 ar_m1 and en_m2 ar_m2 now upon change the lang from en ( english ) to ar ( arabic ) will be that right for one table Example ----->(1)<------ if($lang == "en") $table_name="en_m1"; else if($lang == "ar") $table_name="ar_m1"; $q1 = "select * from $table_name"; $r1 = mysql_query($q1) or die(mysql_error()); $a1 = mysql_fetch_array($r1); till now fine but how it could be done if we have 2 tables such as $q1 = "select * from m1"; $r1 = mysql_query($q1) or die(mysql_error()); $a1 = mysql_fetch_array($r1); $q2 = "select * from m2"; $r2 = mysql_query($q2) or die(mysql_error()); $a2 = mysql_fetch_array($r2); Hope you friends got what i mean ?? how i then for 2 or more tables i can write the exchange code btw tables upon lang just as example (1) thanks in advance Link to comment https://forums.phpfreaks.com/topic/176416-change-btween-tables/ Share on other sites More sharing options...
charlesg Posted October 3, 2009 Share Posted October 3, 2009 I can't understand your question. Sorry. But I really think you would benefit from working with a Framework like CodeIgniter or Kohana. They greatly reduce the time and complexity of working with databases and PHP. Link to comment https://forums.phpfreaks.com/topic/176416-change-btween-tables/#findComment-929873 Share on other sites More sharing options...
egturnkey Posted October 3, 2009 Author Share Posted October 3, 2009 any help :- i mean how to write such as if($lang == "en") $table_name="en_m1"; else if($lang == "ar") $table_name="ar_m1"; $q1 = "select * from $table_name"; $r1 = mysql_query($q1) or die(mysql_error()); $a1 = mysql_fetch_array($r1); if($lang == "en") $table_name2="en_m2"; else if($lang == "ar") $table_name2="ar_m2"; $q2 = "select * from $table_name2"; $r2 = mysql_query($q2) or die(mysql_error()); $a2 = mysql_fetch_array($r2); indeed that is wrong and will gives error so any idea how i do such thing... thanks in advance Link to comment https://forums.phpfreaks.com/topic/176416-change-btween-tables/#findComment-929903 Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 Assumably the tables all have different uses. For example an e-commerce site may have a three tables, Products, Categories and Manufacturers. So assuming your objective is to have different language versions of the tables it would work as so. // get language setting, most likely 'sensible' place would be from $_SESSION array but for simplicity // well declare it here $language = "en"; // you would fetch products like so mysql_query("SELECT * FROM {$language}_Products") // you would fetch manufacturers like so mysql_query("SELECT * FROM {$language}_Manufacturers") // etc and so fourth This is untested, just a theory, but it should work. Link to comment https://forums.phpfreaks.com/topic/176416-change-btween-tables/#findComment-929925 Share on other sites More sharing options...
egturnkey Posted October 3, 2009 Author Share Posted October 3, 2009 cags thanks you so much . this is very smart idea i've test it and works fine. Link to comment https://forums.phpfreaks.com/topic/176416-change-btween-tables/#findComment-929934 Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 Your welcome, please mark the thread as solved (theres a button at the bottom left of your screen). Link to comment https://forums.phpfreaks.com/topic/176416-change-btween-tables/#findComment-929939 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.