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 12 of 12
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts

    Selecting (all) from a field

    Does anyone know how I can select (all) from a specific field, in this case - .category"?
    Something like:

    select id from products where category = *


    I am using it for:

    PHP Code:
    if ($_POST['category'] == "(Any)") {
    $_POST['category'] = "*"
    ... then I'd be using:
    select id from products where category = ".$_POST['category']."
    Last edited by FlashDance; 09-30-2011 at 11:03 AM.

  • #2
    New Coder
    Join Date
    Apr 2010
    Location
    Norfolk, England
    Posts
    63
    Thanks
    1
    Thanked 14 Times in 14 Posts
    Hi FlashDance

    no need for the where clause.


    the query:
    select id from products

    by itself will return all the IDs.
    //Improvement in coding is iterative, each 'failure' is just the next step on your learning curve, some knowledge and logic can get you a long way.//

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    Hi,

    This code won't help because it is not basing the id's off category.
    Last edited by FlashDance; 09-30-2011 at 10:42 AM.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Something like:

    select id from products where category = *
    Code:
    select id from products
    ... then I'd be using:
    select id from products where category = ".$_POST['category']."
    Why would you need to do that?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    Its too complex to explain.

    ... so do you know how it can be done?
    Last edited by FlashDance; 09-30-2011 at 11:11 AM.

  • #6
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Code:
    select id from products
    Quote Originally Posted by FlashDance View Post
    Hi,

    This code won't help because it is not basing the id's off category.
    .....

  • #7
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    I've been asking all around the internet if anyone know how I can select (all) from a specific field (in this case - category), but no one seems to be able to give me a straight answer, its either an answer that does not address my question which was given based on an incorrect assumption that they know what I am trying to do, or some coding preacher trying telling me to code this way, and when I say I don't wish to do that because I feel comfortable my way, the person arrogantly turns around and says "well, I'm not helping you!".

    People really need to learn how to have a no-bull **** conversation, instead of kicking **** into peoples faces.

    This isn't directed at anyone on codingforums.com... am just saying how hard it is to get a simple answer when asking for help from computer programmers.
    Last edited by FlashDance; 09-30-2011 at 12:17 PM.

  • #8
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,303
    Thanks
    4
    Thanked 204 Times in 201 Posts
    Based on your original post the answer provided in post number 2 is correct. If you are intent on using a WHERE clause, as shown in the last example of your original post, change it to:
    Code:
    SELECT `id` FROM `products` WHERE `category` LIKE '%'
    That should get you all of the IDs regardless of their category which is what you appear to be asking for (the answer in post 2 should get you the same results).
    Dave .... HostMonster for all of your hosting needs

  • Users who have thanked djm0219 for this post:

    FlashDance (10-01-2011)

  • #9
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    Dear djm0219,


    I tried your code and got this:
    http://i52.tinypic.com/107m7tg.png

  • #10
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    Ok, your code was actually correct. Appology!

    SOMEHOW "mysql> " got in the code!!

  • #11
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    I am trying to thank you, but there is an error due to me using a web proxy to access this site. I will login directly later on when my connection throttle to 72kbps has been lifted.

    Thanks in the mean time!

  • #12
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    Quote Originally Posted by FlashDance View Post
    I've been asking all around the internet if anyone know how I can select (all) from a specific field (in this case - category), but no one seems to be able to give me a straight answer, its either an answer that does not address my question which was given based on an incorrect assumption that they know what I am trying to do, or some coding preacher trying telling me to code this way, and when I say I don't wish to do that because I feel comfortable my way, the person arrogantly turns around and says "well, I'm not helping you!".
    The problem though could be the way you are asking a question or the fact that you come to the forum(s) with a specific answer in mind and you aren't willing to listen to other people's ideas.

    Remember you may be explaining your problem in a way that makes sense to you, but it may be that you are not explaining it a straight forward as you believe you are and THAT may contribute to the problem as well.


  •  

    Posting Permissions

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