...

View Full Version : Selecting only one field at a time where multiple rows have the same value



amars1983
04-24-2009, 11:03 PM
Newbie here, so if this doesn't make sense I'm sorry. I'm creating a comments area on a page where users can comment on content. I would like to preview a comment before it is posted, so I've created a page where a comment is posted before going to the final database where it is selected from to post onto the final page. I've added a field with a boolean value, so if false, it hasn't been viewd before. If I select all fields that hold false, how can I pull them out one at a time instead of all at once?

Killermud
04-24-2009, 11:18 PM
When you say 'getting all the fields' do you mean using the mysql query :


SELECT * FROM table_name

if so then all you need to do is change your mysql query to :


SELECT field_name FROM table_name

amars1983
04-24-2009, 11:38 PM
Thanks for the quick reply. I have that query, but what I'm saying is I have multiple fields with the same value and I only want to pull out one at a time.

Old Pedant
04-25-2009, 12:15 AM
SELECT * FROM rawcomments
WHERE reviewedflag = false
ORDER BY whenposted
LIMIT 1


LIMIT 1 in MySQL means "only get one"

The ORDER BY will ensure you get the oldest comment, assuming you record the date and time when a comment was posted.

amars1983
04-25-2009, 12:17 AM
Awesome. That works great. Thanks a ton.

Old Pedant
04-25-2009, 12:19 AM
By the way, you do *NOT* have "multiple fields with the same value."

That implies to a SQL user that you have two or more fields (also known as columns) IN THE SAME RECORD that have the same value.

What you have is multiple RECORDS where the value of the SAME FIELD is duplicated.

It was your terminology that confused Killermud, I would guess.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum