Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Selecting only one field at a time where multiple rows have the same value

    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?

  • #2
    Regular Coder
    Join Date
    Mar 2009
    Location
    United Kingdom
    Posts
    161
    Thanks
    6
    Thanked 28 Times in 28 Posts
    When you say 'getting all the fields' do you mean using the mysql query :

    Code:
    SELECT * FROM table_name
    if so then all you need to do is change your mysql query to :

    Code:
    SELECT field_name FROM table_name

  • #3
    New Coder
    Join Date
    Mar 2009
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Code:
    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.

  • Users who have thanked Old Pedant for this post:

    amars1983 (04-24-2009)

  • #5
    New Coder
    Join Date
    Mar 2009
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Awesome. That works great. Thanks a ton.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •