Pieter Posted April 19, 2006 Share Posted April 19, 2006 I have this table called tblTextIt has 4 columns:- text_ID- language_ID- label- texttext_ID = Unique number (prim key)language_ID = 1 or 2 or ... (1 = Dutch, 2 = English)label = label to where the text points (ex. lblTitle)text = de text that will be placed in the label (ex. Hello or Hallo or ...)example of 2 records: text_ID | lang_ID | lable | text |1 | 1 | lbltitel | Hallo |2 | 2 | lbltitel | Hello | Now i would like, using SQL get the following structure: lable | text1 | text2 example: lbltitle | Hallo | Hello Is this possible?It's not necessary that I actually create a new table, creating a select like this: select label,tekst1,tekst2 from tblText would be actually better.I'm using SQL in VB.NET 2005 with ASP.NET and C#many thanks in advance! Link to comment Share on other sites More sharing options...
aspnetguy Posted April 19, 2006 Share Posted April 19, 2006 They are seperate records. A Select just Selects 1 record at a time. You can't do that....not anyway I know how. Link to comment Share on other sites More sharing options...
Pieter Posted April 20, 2006 Author Share Posted April 20, 2006 They are seperate records. A Select just Selects 1 record at a time. You can't do that....not anyway I know how.<{POST_SNAPBACK}> then could i just make a new table out of it? in stead of making a select? Link to comment Share on other sites More sharing options...
justsomeguy Posted April 20, 2006 Share Posted April 20, 2006 What are you trying to do? What is the relationship between text1 and text2? Are you saying you want to get all text fields that have the same label? Link to comment Share on other sites More sharing options...
Pieter Posted April 21, 2006 Author Share Posted April 21, 2006 What are you trying to do? What is the relationship between text1 and text2? Are you saying you want to get all text fields that have the same label?<{POST_SNAPBACK}> yup that's what i want...text1 and text2 have the same label but are in a different row,I want a result so i can get the label and text1 and text2 in the same row in differenct columns. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 21, 2006 Share Posted April 21, 2006 OK, well you don't get one row like that, but you can build it yourself. You will make a query to the database, and get back a bunch of rows, and you can output everything in the same row. I'll give the example in PHP. But this is the query: SELECT * FROM tblText ORDER BY label This will give you a lot of rows. Then you need to loop through the result set, and output the row for each label. When the label changes, you start a new row (for the new label). This is how in PHP: <?php$result = mysql_query("SELECT * FROM tblText ORDER BY label");$last_label = "";while ($row = mysql_fetch_assoc($result)){ if ($row['label'] != $last_label) { echo "<br>"; // new row echo $row['label']; // print the label $last_label = $row['label']; //keep track of the last label } echo $row['text']; // print the text on the row}?> Of course you need some extra formatting in there (spaces between the text, or an html table, whatever), but that's the basic info. Link to comment Share on other sites More sharing options...
Pieter Posted May 2, 2006 Author Share Posted May 2, 2006 OK, well you don't get one row like that, but you can build it yourself. You will make a query to the database, and get back a bunch of rows, and you can output everything in the same row. I'll give the example in PHP. But this is the query:SELECT * FROM tblText ORDER BY label This will give you a lot of rows. Then you need to loop through the result set, and output the row for each label. When the label changes, you start a new row (for the new label). This is how in PHP: <?php$result = mysql_query("SELECT * FROM tblText ORDER BY label");$last_label = "";while ($row = mysql_fetch_assoc($result)){ if ($row['label'] != $last_label) { echo "<br>"; // new row echo $row['label']; // print the label $last_label = $row['label']; //keep track of the last label } echo $row['text']; // print the text on the row}?> Of course you need some extra formatting in there (spaces between the text, or an html table, whatever), but that's the basic info. <{POST_SNAPBACK}> great thx...you helped me out a lot! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now