Solved

Mysql reference table sql sentence

Posted on 2011-02-15
5
431 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

695 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