Results 1 to 5 of 5
  1. #1
    ABW Ambassador Steveinid's Avatar
    Join Date
    January 18th, 2005
    Posts
    827
    I am trying to display all items by category. Initially I used the following line to display everything:

    $sql = "SELECT * FROM $table_name
    ORDER BY title";

    That worked well. Now I want to display by category. In this case "cat" is category. I used the following:

    $sql = "SELECT * FROM $table_name
    WHERE cat = womens
    ORDER BY title";

    This doesn't work. It says "couldn't execute query" Am I missing something? Can you not use a * with the WHERE command?

    Thanks

    "Bueller...? Bueller...?"

  2. #2
    Just Lurking
    Join Date
    January 18th, 2005
    Posts
    1,263
    try some single quotes like this:

    $sql = "SELECT * FROM $table_name
    WHERE cat = 'womens'
    ORDER BY title";

    Might want to try this too:

    $sql = "SELECT * FROM $table_name
    WHERE cat LIKE 'womens'
    ORDER BY title";

    ------------------------------
    "A man is but the product of his thoughts. What he thinks, he becomes." -- Mahatma Gandhi

  3. #3
    Just Lurking
    Join Date
    January 18th, 2005
    Posts
    1,263
    If your still having trouble?

    You can use these two wildcards with the LIKE string comparison:

    % Matches any number of characters, even zero characters
    _ Matches exactly one character


    Might try this:

    $sql = "SELECT * FROM $table_name
    WHERE cat LIKE '%women%'
    ORDER BY title";

    in case your `cat` field is full of garbage.

    ------------------------------
    "A man is but the product of his thoughts. What he thinks, he becomes." -- Mahatma Gandhi

  4. #4
    ABW Ambassador Steveinid's Avatar
    Join Date
    January 18th, 2005
    Posts
    827
    SWEEEEET!!!
    It worked... It was the single quotes that worked. I thought I had tried that but I guess not. Thanks for the help Buddha.

    "Bueller...? Bueller...?"

  5. #5
    Just Lurking
    Join Date
    January 18th, 2005
    Posts
    1,263
    Your welcome.

    ------------------------------
    "A man is but the product of his thoughts. What he thinks, he becomes." -- Mahatma Gandhi

  6. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. PHP/MySQL programmer needed
    By Verdant in forum Member Services
    Replies: 5
    Last Post: March 8th, 2014, 07:58 AM
  2. PHP question - include(file.php) with variables
    By teezone in forum Programming / Datafeeds / Tools
    Replies: 8
    Last Post: September 4th, 2009, 04:54 PM
  3. Custom Database(MyPhpAdmin) and PHP Needed
    By CustomersFirst in forum Couponer's Corner
    Replies: 0
    Last Post: March 15th, 2008, 03:41 PM
  4. PHP Know-how needed please
    By MoneyBusiness in forum Programming / Datafeeds / Tools
    Replies: 7
    Last Post: September 20th, 2006, 05:54 PM

Posting Permissions

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