Solved

Mysql reference table sql sentence

Posted on 2011-02-15
5
425 Views
Last Modified: 2012-08-13
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
Comment
Question by:Braveheartli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
Kalpan earned 334 total points
ID: 34894780
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
 
LVL 1

Author Comment

by:Braveheartli
ID: 34894855
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
 
LVL 14

Assisted Solution

by:Kalpan
Kalpan earned 334 total points
ID: 34894893
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
 
LVL 34

Assisted Solution

by:Beverley Portlock
Beverley Portlock earned 166 total points
ID: 34896586
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
 
LVL 1

Author Closing Comment

by:Braveheartli
ID: 34914885
thank you
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Creating and Managing Databases with phpMyAdmin in cPanel.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question