0

I'm working on a project which requires more than one column contents to be passed to a php variable

I am able to select and pass one column content to the variable but failed on multiple columns

$myEMPNEM = "";

$sqlNEM = "SELECT first_name, middle_name, last_name, job_title FROM 
t_employees WHERE user_name = '" . $_SESSION["uname"] . "'";
$resultNEM = mysqli_query( $conn, $sqlNEM );
while($row = mysqli_fetch_array($resultNEM))
{
  $myEMPNEM = $row['first_name'];   
 }

I expect more than one column content to be passed to the php variable

1 Answers1

1

You either need to use the variable as an array:

while($row = mysqli_fetch_array($resultNEM))
{
  $myEMPNEM = array($row['first_name'], $row['middle_name'], $row['last_name']);   
}

Or concatenate the values together into a single string:

while($row = mysqli_fetch_array($resultNEM))
{
  $myEMPNEM = $row['first_name'] . " " . $row['middle_name'] . " " . $row['last_name'];
}
gmiley
  • 6,531
  • 1
  • 13
  • 25