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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2010
    Location
    Earth
    Posts
    305
    Thanks
    27
    Thanked 2 Times in 2 Posts

    pulling info from a search

    Not sure how to explain this, so please bear with me.

    I am trying to verify if a userName is in a query but not sure how to check for it. There can be one 2 names in the query and I need to check to see if one ($clientID) is in it.

    user has to be logged in so $clientID is set

    My code:

    PHP Code:
      $sql mysql_query("SELECT author FROM replies WHERE thread=$id");
      while(
    $r mysql_fetch_array($sql)) {
        
    $author=$r['author'];
      }

      if(
    $author==$clientID){    
    echo 
    "True";
      }
      else {
        echo 
    "False";
      } 

    So $author is either one of 2 names, $clientID or whatever
    so for example - the author table

    $author
    Jack
    Jill
    Jill
    Jack
    Jill

    With Jack = $clientId

    when I run the query it will be false because Jill comes up last, but I need it to be true because Jack was in it as well.
    Last edited by harkly; 11-22-2010 at 05:58 PM.

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code your query correctly.

    Code:
    $sql = mysql_query('SELECT author FROM replies WHERE thread='.intval($id).' AND author=\''.mysql_real_escape_string($clientID).'\' LIMIT 1');
    
    if (mysql_num_rows($sql))
    {
        [the author was found]
    }
    else
    {
        [the author was not found]
    }
    That's assuming that $id is an integer, btw. If it's alphanumeric, use the real_escape_string on that instead.

  • #3
    Regular Coder
    Join Date
    Jun 2010
    Location
    Earth
    Posts
    305
    Thanks
    27
    Thanked 2 Times in 2 Posts
    That won't help with my search issue.

    Looks like I need to search the array for the $clientID

    Working on this right now

    PHP Code:
      $sqlImage mysql_query("SELECT author FROM replies WHERE thread=$id");
      while(
    $r mysql_fetch_array($sqlImage)) {
        
    $author=$r['author'];
        
    $authorArray = array($author);

        if(
    in_array($clientID$authorArray)){
          
    $result='true';}
        else{
          
    $result='false';
        }
      } 

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by harkly View Post
    That won't help with my search issue.
    Why? If you work on the assumption that we're not pyschic and actually give a useful description of what you're trying to do, maybe you'll receive answers which are more relevant.

  • #5
    Regular Coder
    Join Date
    Jun 2010
    Location
    Earth
    Posts
    305
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Sorry, MattF, your code did work, I had another issue that was messing up the results.


  •  

    Posting Permissions

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