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
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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.