1

I want to get the first_name and the last_name from a database.
I select them, but then I'm unable to return both with a space in-between them, and need it to be returned not echoed because I am going to use it as a link for the user profile.

function getuser ($id, $field_one, $field_two) {
$query = mysql_query("SELECT $field_one, $field_two FROM users WHERE user_id='$id'");
$run = mysql_fetch_array($query);
return $run[$field_one, $field_two];

}

I think the problem is in the last 2 lines

$run = mysql_fetch_array($query);
return $run[$field_one];

2 Answers 2

2

Try this:

return $run[$field_one] . " " . $run[$field_two];

BTW you have to change your query to:

"SELECT {$field_one}, {$field_two} FROM users WHERE user_id={$id}"

Take a look at this for examples: http://php.net/manual/en/function.mysql-fetch-array.php

Sign up to request clarification or add additional context in comments.

Comments

0

If you always need the full name you might use something like SELECT CONCAT(firstname, " ", lastname) as fullname FROM table already in your SQL.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.