Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-28-2012, 05:21 PM   PM User | #1
schalk1807
New to the CF scene

 
Join Date: May 2012
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
schalk1807 is an unknown quantity at this point
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;
    }
    
    } 
schalk1807 is offline   Reply With Quote
Old 10-28-2012, 07:03 PM   PM User | #2
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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']; 
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Users who have thanked tangoforce for this post:
schalk1807 (10-28-2012)
Old 10-28-2012, 07:07 PM   PM User | #3
schalk1807
New to the CF scene

 
Join Date: May 2012
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
schalk1807 is an unknown quantity at this point
Thanx for your reply.

changed it using your code.

no change
schalk1807 is offline   Reply With Quote
Old 10-29-2012, 12:18 AM   PM User | #4
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
In that case you need to run the SQL statement in phpmyadmin in the SQL page and see what happens.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:42 PM.


Advertisement
Log in to turn off these ads.