Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2006
    Location
    Ontario Canada
    Posts
    4,587
    Tokens
    0

    Latest Awards:

    Default variable in mysql

    i have this query:
    $result = mysql_query("SELECT * FROM comments WHERE userwall='Colin Roberts' ORDER BY id DESC");

    i want userwall to be a variable in relation to whose logged in.. how do i do this?

    <?php echo $loggedin['username']; ?> echo's the the name of logged in user

    .:.:#14:.:. .:.: Impossible Is Nothing :.:. .:.: 845 Rep:.:.
    .:.: Stand up for what is right, even if you stand alone:.:.


  2. #2
    Join Date
    Feb 2006
    Location
    Ontario Canada
    Posts
    4,587
    Tokens
    0

    Latest Awards:

    Default

    wow nvm i figured it out

    .:.:#14:.:. .:.: Impossible Is Nothing :.:. .:.: 845 Rep:.:.
    .:.: Stand up for what is right, even if you stand alone:.:.


  3. #3
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default

    PHP Code:
    $result = mysql_query("SELECT * FROM comments WHERE userwall='<?php echo $loggedin['username']; ?>' ORDER BY id DESC");
    Wow, Im glad you figured that out lol

    Lew.
    Im not here to be loved, I love to be hated :-}


  4. #4
    Join Date
    Feb 2006
    Location
    Ontario Canada
    Posts
    4,587
    Tokens
    0

    Latest Awards:

    Default

    lewie for the record your way doesn't work, it gives errors.

    .:.:#14:.:. .:.: Impossible Is Nothing :.:. .:.: 845 Rep:.:.
    .:.: Stand up for what is right, even if you stand alone:.:.


  5. #5
    Join Date
    Aug 2009
    Posts
    78
    Tokens
    100

    Latest Awards:

    Default

    Quote Originally Posted by Lewiie15 View Post
    PHP Code:
    $result = mysql_query("SELECT * FROM comments WHERE userwall='<?php echo $loggedin['username']; ?>' ORDER BY id DESC");
    Wow, Im glad you figured that out lol

    Lew.
    If you're using a result variable... you're going to have the PHP tags open already.
    PHP Code:
    $result mysql_query("SELECT * FROM comments WHERE userwall = $loggedin['username'] ORDER BY id DESC"); 
    should work fine... I've not used PHP in a long time.

  6. #6
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Colin-Roberts View Post
    lewie for the record your way doesn't work, it gives errors.
    Sorry lol, I should of known that. I was at work at the time

    PHP Code:
    $result mysql_query("SELECT * FROM `comments` WHERE` userwall` = '" $loggedin['username'] . "' ORDER BY `id` DESC"); 
    Thats how I would have coded it I like my full stops lol

    Lew.
    Im not here to be loved, I love to be hated :-}


  7. #7
    Join Date
    Apr 2010
    Location
    Newcastle
    Posts
    655
    Tokens
    50

    Default

    Quote Originally Posted by Lewiie15 View Post
    Sorry lol, I should of known that. I was at work at the time

    PHP Code:
    $result mysql_query("SELECT * FROM `comments` WHERE` userwall` = '" $loggedin['username'] . "' ORDER BY `id` DESC"); 
    Thats how I would have coded it I like my full stops lol

    Lew.
    Your backquotes are messed up

    PHP Code:
    $result mysql_query("SELECT * FROM `comments` WHERE `userwall` = '".mysql_real_escape_string($loggedin['username'])."' ORDER BY `id` DESC;"); 

  8. #8
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Apolva View Post
    Your backquotes are messed up

    PHP Code:
    $result mysql_query("SELECT * FROM `comments` WHERE `userwall` = '".mysql_real_escape_string($loggedin['username'])."' ORDER BY `id` DESC;"); 
    Lol, I did it quickly I like to have spaces between my " . "'s lol

    Lew.
    Im not here to be loved, I love to be hated :-}


Posting Permissions

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