Jump to content

change btween tables...!


egturnkey

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.