Jump to content

select multiple rows as one row ?


anatak

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/174410-select-multiple-rows-as-one-row/
Share on other sites

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.