Jump to content

PHP/Mysql create a common field


c_pattle

Recommended Posts

I was wondering if anyone know's how to create a field in a mysql query.  For example if I have a query such as "select * from names" is there a way to add a field that automatically increment for search row.  So for example the query would then return a list of names each with a unique number (e.g 1-10) even though this field is not in the database. 

 

I want to do this because I want to join two query and I want to create a common field which both queries will have. 

 

Thanks for any help. 

Link to comment
Share on other sites

Thanks, I need to do it because I need to join 2 tables together. 

 

I tried using a left join but because there are no common fields it means that I just got "null" for all of the values from the right table.  However if I have a common field then the join will work.  Hope that makes sense. 

Link to comment
Share on other sites

Thanks, I need to do it because I need to join 2 tables together. 

 

I tried using a left join but because there are no common fields it means that I just got "null" for all of the values from the right table.  However if I have a common field then the join will work.  Hope that makes sense.

 

No really... doesn't make sense... doesn't "smell" good ... what are you trying to do exactly?... maybe the description of your 2 tables and a little explanation of your objectives will help you to get another point of view

Link to comment
Share on other sites

Yeah I am open to suggestions on how to make it better. 

 

Basically I have two tables that are completely unrelated.  I want to have a query that will get the most recent 10 rows from both tables but will merge the two tables into one.  I want to do this because it will be a lot easier when I come to actually doing something with the data. 

 

For example if I do..

 

while ($array = mysql_fetch_array($rs)) {

 

It will be a lot lot easier if all the data I need is on the same row. 

Link to comment
Share on other sites

Here are the two tables that I have.  With both tables I have included an examples of the latest row that could have been entered.  The first is a table called "articles". 

 

article_numberarticle_titlearticle_descriptionarticle_authorarticle_link

45Article 1A little description hereChris Pwww.google.com

 

The second is called "announcements". 

 

announcement_numberannouncement_titleannouncement_contentannouncement_link

10Announcement 1 The content for announcementwww.bbc.co.uk

 

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.