Jump to content

returning table name as well as fields from that table


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";

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.