Q:

How to convert a column data to a row in php mysql

This is basically for testing an address book php application. 
Here is the output I got from the SQL query. I want to convert this results to a row.
MySQL Query output

Output looking for

A:

Query
SELECT contact_id,
MAX(First_name) AS First_name,
MAX(Last_Name) AS Last_Name,
MAX(Primary_Email) AS Primary_Email,
MAX(Primary_phone) AS Primary_phone
FROM (
SELECT MIN(contact_id) as contact_id,
CASE WHEN meta_data='First_Name' THEN meta_value END AS First_Name,
CASE WHEN meta_data='Last_Name' THEN meta_value END AS Last_Name,
CASE WHEN meta_data='Primary_Email' THEN meta_value END AS Primary_Email,
CASE WHEN meta_data='Primary_phone' THEN meta_value END AS Primary_phone
FROM tbl
GROUP BY contact_id,meta_data,meta_value
) t
GROUP BY contact_id

Fiddle demo

