• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 456
  • Last Modified:

Mysql reference table sql sentence

I use PHP and MySQL
I have two tables. One of them is my main table named MAINTABLE
I have many coloumns in this table.

I have a referance table named RT_REFERANS_TAB2 whis has the values for my city names and languages
it is like below.

RT_REFERANS_TAB2

id       rt_name       rt_id       rt_value
1       rt_sehir       1             New York
2       rt_sehir      2             Paris
97       rt_lang       1             German
98       rt_lang       2             English

MAINTABLE

id  City      Language1

I need to write an sql sentence to merge my main table and reference table and give out the desired results.

I insert into main talbe "1" for New York and 2 for Paris.
What I need to do is when I select form my database I want it to show  the city name not the number.
thank you
0
Braveheartli
Asked:
Braveheartli
  • 2
  • 2
3 Solutions
 
KalpanCommented:
please refer the following query, which will fetch the city as name related to MAINTABLE with join query from RT_REFERANS_TAB2

select rt.rt_value as city from MAINTABLE mt LEFT JOIN RT_REFERANS_TAB2 rt on mt.id=rt.rt_id;

hope that helps...

kalpan
0
 
BraveheartliMarketingAuthor Commented:
Dear kalmax,
I write it like this, nothing happens..

$sql2="select rt.rt_value as City from MAINTABLE mt LEFT JOIN RT_REFERANS_TAB2 rt on mt.id=rt.rt_id";
 
$result = mysql_query($sql2)
or die(mysql_error());  

while($row = mysql_fetch_array( $result )) {
      // Print out the contents of each row into a table

      $sehirmail= $row['City'];

       }

echo $sehirmail;
0
 
KalpanCommented:
make sure you have the entries that should match up with the two tables using join query...

let it run the sql query with mysql client first, to check the query works or not...and what it returns than try using php...

0
 
Beverley PortlockCommented:
Try making  this alteration (assuming the query works OK)

$sehirmail .= '<table>\n";

while($row = mysql_fetch_array( $result )) {
      // Print out the contents of each row into a table

      $sehirmail .= "<tr>\n<td>\n{$row['City']}\n</td>\n</tr>\n;

       }

$sehirmail .= '</table>\n";
0
 
BraveheartliMarketingAuthor Commented:
thank you
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now