Solved

Mysql reference table sql sentence

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP installation issues 11 60
paypal ipn to mysql 3 36
Number of hours between date in DB and now 8 18
How to obtain the string from a PHP StdObject ? 6 19
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

773 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