SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Excluding specific user?

    I'm trying to exclude the current user from an sql query, but cant get it to work... Where do I go wrong.
    PHP Code:
    $currentUser $user

    $sql2
    ="SELECT * FROM ".$prefix."_clubnews WHERE newsid='$newsid' OR ori_newsid = '$newsid' AND userid != $currentUser";
                
    $result2 mysql_query($sql2);
                while(
    $row2 mysql_fetch_array($result2)){ 

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    repeat the AND requirement in both OR cases. I am presuming $user is an integer here, else you should quote the value .

    Code sql:
    ".... userid != '$currentUser'";

  3. #3
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jmansa View Post
    I'm trying to exclude the current user from an sql query, but cant get it to work... Where do I go wrong.
    PHP Code:
    $currentUser $user

    $sql2
    ="SELECT * FROM ".$prefix."_clubnews WHERE newsid='$newsid' OR ori_newsid = '$newsid' AND userid != $currentUser";
                
    $result2 mysql_query($sql2);
                while(
    $row2 mysql_fetch_array($result2)){ 

    try this:
    $sql2="SELECT * FROM ".$prefix."_clubnews WHERE (newsid='$newsid' OR ori_newsid = '$newsid') AND userid != $currentUser";


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
  •