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 4 of 4
  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    20
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Question Function not returning expected value

    Can anyone please tell me why this function is returning the user_id as contained in the $friends variable, instead of the first_name and last_name?

    PHP Code:
    public function getFriendsById($friends) {
            
    $sql="SELECT first_name, last_name FROM users WHERE user_id ="$friends;
            
    $results mysql_query($sql)or die("Selection Query Failed !!!");
            
    $friendsNames = array();
            while (
    $row mysql_fetch_array($results)){
                
    $friendsNames[] = $row['first_name, last_name'];
                }
            return 
    $friendsNames;
        }
        
        } 

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,316
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Quote Originally Posted by schalk1807 View Post
    Can anyone please tell me why this function is returning the user_id as contained in the $friends variable, instead of the first_name and last_name?

    PHP Code:
    $friendsNames[] = $row['first_name, last_name']; 
    You can't do that. The best you can do is this:

    PHP Code:
    $friendsNames[] = "$row[first_name], $row[last_name]";

    //OR
    $friendsNames[] = $row['first_name'] .', '  .$Row['last_name']; 
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    schalk1807 (10-28-2012)

  • #3
    New Coder
    Join Date
    May 2012
    Posts
    20
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Thanx for your reply.

    changed it using your code.

    no change

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,316
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    In that case you need to run the SQL statement in phpmyadmin in the SQL page and see what happens.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

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