SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Evangelist Caesar's Avatar
    Join Date
    May 2000
    Location
    On some harddisk
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let's suppose that I have the following PHP code in one of my files.

    $myselect = "select * FROM thread WHERE forumid<>5 ORDER BY lastpost DESC LIMIT 10";

    How do I also exclude threads where they come from forumid 18 or 19?

    I tried:

    $myselect = "select * FROM thread WHERE forumid<>5 OR forumid<>18 or forumid<>19 ORDER BY lastpost DESC LIMIT 10";

    but it wouldn't work. Can someone tell me how do I do it the right way?

  2. #2
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What error, or problem are you getting when you run that page.

    To admin i've never seen the: <>
    Thing before. What is it, if it means = then just use that.

  3. #3
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You want to select all the records except thos records with a forumid of 5,18 and 19? Is that right? You need to use logical AND not OR. If I am correct that sql statement will be returning all the records. Right?
    PHP Code:
    $myselect "SELECT *
                 FROM thread
                 WHERE forumid <> 5
                 AND forumid <> 18
                 AND forumid <> 19
                 ORDER BY lastpost DESC 
                 LIMIT 10"

    With logical OR only one of the conditions needs to be true for the result to evaluate to true. So if you construct a truth table you can see that all records will evaluate to true:
    Code:
       | <>5  | <> 18  | <> 19 | <>5  OR <> 18  OR <> 19 
    5  |    F |     T   |      T  |  T
    18 |    T |     F   |     T   |   T
    19 |    T |     T   |     F   |   T
    Hehe, I don't know if that looks like a table to you - it looks ok in my browser.
    Last edited by freakysid; Apr 23, 2001 at 04:59.

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pete <> is another way of writing the != (not equal to) comparison operater in MySQL. It is also used in visual basic.
    Last edited by freakysid; Apr 23, 2001 at 05:26.

  5. #5
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok thanks, that changes everything!

    -Peter

  6. #6
    SitePoint Zealot DarkMonkey's Avatar
    Join Date
    Apr 2001
    Location
    uk
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks sid, I was wondering what that did as well.


Bookmarks

Posting Permissions

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