Solved

Mysql reference table sql sentence

Posted on 2011-02-15
5
399 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
  • 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 Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now