Reputation: 219
In my database I have a column "first_name" and "last_name" (there is more in there but not related to my question)
Here is the code :
//Get variables for email
$qry_get = mysql_query("SELECT * FROM members WHERE id = $id");
while($row_get = mysql_fetch_array($qry_get))
{
$id = $row_get['id'];
$name = $row_get['first_name'];
$email = $row_get['email'];
$password = $row_get['password'];
}
And this works fine. But im trying to get $name to fetch both first_name and last_name. Is it possible?
It is so when the details are inserted into the database it will show both names rather than just the first name.
I have tried to do it like
//Get variables for email
$qry_get = mysql_query("SELECT * FROM members WHERE id = $id");
while($row_get = mysql_fetch_array($qry_get))
{
$id = $row_get['id'];
$name = $row_get['first_name'],['last_name'];
$email = $row_get['email'];
$password = $row_get['password'];
}
But it failed.
Upvotes: 1
Views: 223
Reputation: 2448
You shouldn't use SQL, it's open to attack and is deprecated, Look into SQLi or PHP PDO data objects. Why are you selecting all in your query when you only need 2 fields ? I will work with your code though
SELECT first_name,last_name FROM members WHERE id = $id"
Upvotes: 0
Reputation: 6758
You can't get two values at once like you did, you have to concatenate the value of $row_get['first_name']
and the value of $row_get['last_name']
:
//Get variables for email
$qry_get = mysql_query("SELECT * FROM members WHERE id = $id");
while($row_get = mysql_fetch_array($qry_get))
{
$id = $row_get['id'];
$name = $row_get['first_name'] . ' ' .$row_get['last_name'];
$email = $row_get['email'];
$password = $row_get['password'];
}
Upvotes: 1