anatak Posted September 16, 2009 Share Posted September 16, 2009 Hello, Is it possible to select multiple rows in one query but return them as one row ? I have a table called language with 2 fields Id (int 11) Language (varchar 255) the values are 1 English 2 Japanese 3 French def_lan = default language from_lan = the language to translate from to_lan = the language to translate to Is it possible to select the values that they are in 1 row like this ? def_lan_id => 1, from_lan_id => 3, to_lan_id => 2, def_lan=>English, from_lan=>French, to_lan=>Japanese ? disclaimer It is easy to work around this by making 3 queries instead of one and I think it would be better (faster for db and also a lot easier to read the code aftwards) I am just curious if it would be possible to do what I described ? Thanks for reading anatak Quote Link to comment https://forums.phpfreaks.com/topic/174410-select-multiple-rows-as-one-row/ Share on other sites More sharing options...
asmith Posted September 16, 2009 Share Posted September 16, 2009 I actually read 2 times. what are def_lan, from_lan, to_lan? They are PHP variables? and what is this: def_lan_id => 1, from_lan_id => 3, to_lan_id => 2, def_lan=>English, from_lan=>French, to_lan=>Japanese PHP array? Is 1,2,3 only the ID of the language? Or 1 also means default? I'm sorry your post is confusing, At least to me. Can you explain more clear? Quote Link to comment https://forums.phpfreaks.com/topic/174410-select-multiple-rows-as-one-row/#findComment-919333 Share on other sites More sharing options...
anatak Posted September 16, 2009 Author Share Posted September 16, 2009 table language structure Field Type Collation Attributes Null Default Extra Id int(11) No None auto_increment Language varchar(255) utf8_unicode_ci No None rows 1 English 2 French 3 Japanese the $_POST[def_lan], $_POST[from_lan], $_POST[to_lan] values come from a form that is submitted and they are the Id values from the table language the idea is to translate text from another table. I am trying to make a query so that the result from $result=dbconn->GetRow($Query_to_select_the_lang) are in 1 row so if you would do print_r($result) you would get something like array() def_lan_id => 1, from_lan_id => 3, to_lan_id => 2, def_lan=>English, from_lan=>French, to_lan=>Japanese I don't know if this makes it more clear abstractly speaking I want to select 3 rows from a table when you know the primary key for every row and I want the query to return 1 row Quote Link to comment https://forums.phpfreaks.com/topic/174410-select-multiple-rows-as-one-row/#findComment-919352 Share on other sites More sharing options...
fenway Posted September 21, 2009 Share Posted September 21, 2009 "multiple rows as one row" ==> either means you want group-concat or you want joins. Quote Link to comment https://forums.phpfreaks.com/topic/174410-select-multiple-rows-as-one-row/#findComment-922432 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.