Jump to content


Photo

Query Whit 2 Columns

php sql

  • Please log in to reply
6 replies to this topic

#1 madness69

madness69

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts

Posted 08 December 2012 - 01:19 PM

Could someone tell me what is the query for what im trying to do, for example:
i have 2 tables, one is "comments" table and the other is "articles" tables.
In the comments table there is a 3 columns (id, title, message) and in the articles table there is 3 columns too(id, title,info)
I would like is to get all the data of the column message from the table "comments" but the table "comments" got to have the same title of the column title of the column title of Articles table.
I dont no if im beign confusing, im sorry.

#2 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,269 posts
  • LocationCheshire, UK

Posted 08 December 2012 - 04:55 PM

Not much point in storing a title in the comments table then.

How do you know which comments belong to which article?

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#3 madness69

madness69

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts

Posted 08 December 2012 - 05:57 PM

The title given is a unique name and are the same name in the coment and article

Edited by madness69, 08 December 2012 - 05:58 PM.


#4 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,707 posts
  • LocationBonita, FL

Posted 08 December 2012 - 06:57 PM

You should be linking the comments with the article by the article's ID number, not the title.  It's quicker to compare a couple of INTs than it is to compare strings.  It would also use a lot less space on the system to store those INTs than to store a copy of the title.  You also won't have any issues if the article title ever gets changed.

Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#5 madness69

madness69

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts

Posted 08 December 2012 - 07:01 PM

yes i know, and how would be the query for it?

Here is the tables:

table comments:
- id;
- name;
- email;
- message;
-id_article;


table articles:
-id;
- title;
- contents;

Edited by madness69, 08 December 2012 - 07:13 PM.


#6 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,707 posts
  • LocationBonita, FL

Posted 08 December 2012 - 07:10 PM

Just do a JOIN between the two tables using the title columns as the join's condition.
Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#7 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,269 posts
  • LocationCheshire, UK

Posted 08 December 2012 - 07:18 PM

I would like is to get all the data of the column message from the table "comments" but the table "comments" got to have the same title of the column title of the column title of Articles table.


According to to OP all that is required is message column from comments table. I am totally confused about requirements here. It's later been established that title columns are the same so why mention that constraint.

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com