Jump to content

returning table name as well as fields from that table


dc_jt

Recommended Posts

Hi my code is below: I am returning all fields from news and from regional, however I want to determine where the fields have come from when I ouput the data, therefore I need to return the table name with the fields. Is this possible?

 

Something like SELECT *, tablename from news...???

 

$sSql = "SELECT * from news
			WHERE publish_date <= '$now'
			AND hide = '0'
			UNION
			SELECT * from regional
			WHERE publish_date <= '$now'
			AND hide = '0'
			ORDER BY publish_date DESC
			LIMIT 30";

Hi I dont think you quite understand what I mean.

 

I know how to get all the columns but I want to return the table NAME (news and regional) as well as the columns.

 

Therefore, when each column is returned as:

 

id, title, content

id, title, content

 

it will be returned as

 

news, id, title, content

regional, id, title, content

 

So when it is ouput I can see which colums have come from which table.

 

Any idea??

 

Thanks

try

$sSql = "SELECT *, 'news' as table_nam from news
			WHERE publish_date <= '$now'
			AND hide = '0'
			UNION
			SELECT *, 'regional' as table_nam from regional
			WHERE publish_date <= '$now'
			AND hide = '0'
			ORDER BY publish_date DESC
			LIMIT 30";

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.