SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast DaDeViL's Avatar
    Join Date
    Aug 2003
    Location
    USA
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    get just one result

    is there any way to get one specific name from a database

    ...for example, I have a table named user_message
    and a row called the_user which keeps track of which user posted the message,
    but what I want to do is compare the username of the CURRENT_userto the user that posted the message
    (ie. a user already in the row the_user )
    so that another user cant change the same message.

    PHP Code:
    $check_user_query "select * from user_message where

    the_user = \"CURRENT_user\""
    ;

    $check_user mysql_query($check_user_query) or

    die(
    mysql_error());

    if(
    mysql_num_rows($check_user) != 0){

    return 
    "TRUE";

    } else {

    return 
    "FALSE";


    When i use this, it always returns true...no matter what value i put in for CURRENT_user

    Thanks

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    it will return FALSE if you put in a value for a user that has not posted a message

    in effect, you are saying "get all the messages for user X, and if there are any, return TRUE"
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast DaDeViL's Avatar
    Join Date
    Aug 2003
    Location
    USA
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so what query should i use to check if the current user is the same as the one specific user that posted the message?

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    select the_user
    from user_messages
    where message_id = N

    you need to specify which message you're talking about

    the query will return exactly one result

    then compare this in your code to the current user
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •