You could denormalize the data on output in your query, like this (Grouping on userdb_id
):
SELECT
MAX(CASE WHEN userdbelements_field_name = 'user_first_name'
THEN userdbelements_field_value ELSE NULL END) AS first_name,
MAX(CASE WHEN userdbelements_field_name = 'user_last_name'
THEN userdbelements_field_value ELSE NULL END) AS last_name,
MAX(CASE WHEN userdbelements_field_name = 'City'
THEN userdbelements_field_value ELSE NULL END) AS city,
MAX(CASE WHEN userdbelements_field_name = 'state'
THEN userdbelements_field_value ELSE NULL END) AS state,
MAX(CASE WHEN userdbelements_field_name = 'zip'
THEN userdbelements_field_value ELSE NULL END) AS zip,
MAX(CASE WHEN userdbelements_field_name = 'phone'
THEN userdbelements_field_value ELSE NULL END) AS phone,
FROM userdbelemnts
GROUP BY userdb_id
Then in your php, just loop through the results as you would in a flat table.
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>City</th>
<th>State</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
<?php while ($row = mysqli_fetch_assoc($result)) { ?>
<tr>
<td><?=$row['first_name']?></td>
<td><?=$row['last_name']?></td>
<td><?=$row['city']?></td>
<td><?=$row['state']?></td>
<td><?=$row['phone']?></td>
</tr>
<?php } ?>
</tbody>
Edit: given your new table schema per comments below:
SELECT
orodha_en_userdb.*,
MAX(CASE WHEN userdbelements_field_name = 'user_first_name'
THEN userdbelements_field_value ELSE NULL END) AS first_name,
MAX(CASE WHEN userdbelements_field_name = 'user_last_name'
THEN userdbelements_field_value ELSE NULL END) AS last_name,
MAX(CASE WHEN userdbelements_field_name = 'City'
THEN userdbelements_field_value ELSE NULL END) AS city,
MAX(CASE WHEN userdbelements_field_name = 'state'
THEN userdbelements_field_value ELSE NULL END) AS state,
MAX(CASE WHEN userdbelements_field_name = 'zip'
THEN userdbelements_field_value ELSE NULL END) AS zip,
MAX(CASE WHEN userdbelements_field_name = 'phone'
THEN userdbelements_field_value ELSE NULL END) AS phone,
FROM orodha_en_userdbelements
INNER JOIN orodha_en_userdb
ON orodha_en_userdbelements.userdb_id = orodha_en_userdb.userdb_id
WHERE orodha_en_userdb.userdb_id = $id
GROUP BY orodha_en_userdb.userdb_id
separating
' it? – Cthulhu Jun 15 '13 at 12:41user_id
in that table? Is the table calleduserdbelements
? – Steven Moseley Jun 15 '13 at 12:41userdbelements
. and also column is there calleduserdb_id
– user2178637 Jun 15 '13 at 12:44