I'm using Wordpress and I have to figure out how to get multiple values out of the same column and turn them into variables.

The last step is I just want the data to display in a table like so:

```
Bob Company1 <br>
Alex Company2

```

Instead I get either `Bob Alex Company1 Company 2` or  

```
Bob <br>
Alex<br>
Company1<br>
Company2

```

Here's two different versions I'm working with:

```
$sql = "SELECT meta_value as guest from wp_postmeta INNER JOIN wp_posts ON wp_posts.ID  = wp_postmeta.post_id WHERE post_type='guests' AND meta_key='guest_name' UNION SELECT meta_value as company from wp_postmeta INNER JOIN wp_posts ON wp_posts.ID = wp_postmeta.post_id WHERE post_type='guests' AND meta_key='guests_company'";
$result = mysql_query($sql);
$NumberOfResults=mysql_num_rows($result);

if (mysql_num_rows($result) == 0) {
    echo "No Guests yet... stay tuned!";
    exit;
}

while(list($guest,$company)= mysql_fetch_row($result)) 
{ 
    echo "<table><tr><td>".$guest."</td><td>".$company."</td></tr></table>";
}

```

or

```
$sql = mysql_query("SELECT meta_value as guest from wp_postmeta INNER JOIN wp_posts ON wp_posts.ID = wp_postmeta.post_id WHERE post_type='guests' AND meta_key='guest_name' LIMIT 2 UNION SELECT meta_value as company from wp_postmeta INNER JOIN wp_posts ON wp_posts.ID = wp_postmeta.post_id WHERE post_type='guests' AND meta_key='guests_company'");

$i = 1;
while ($get = mysql_fetch_array($sql))
{
    echo '<table><tr><td>'.$get["guest"].'</td><td>'.$get["company"].'</td></tr></table>';

    $i++;
}

```

ANY HELP would be so appreciated!!! thanks!

Edit: In case anybody in the future wants to create their own widget using advanced custom fields in Wordpress, here's the final product more or less:

```
$sql = "SELECT p.ID AS post_id, g.meta_value as guest, c.meta_value as company, d.meta_value as date
FROM wp_posts p
JOIN wp_postmeta g ON g.post_id = p.id AND g.meta_key = 'guest_name'
JOIN wp_postmeta c ON c.post_id = p.id AND c.meta_key = 'guests_company'
JOIN wp_postmeta d ON d.post_id = p.id AND d.meta_key = 'show_date'
WHERE p.post_status = 'publish'
ORDER by d.meta_value DESC";

$query = mysql_query($sql);

echo '<table><tr><th>Guest</th><th>Company</th><th>Show Date</th></tr>';
while ($get = mysql_fetch_array($query)) {$newDate = date("m-d-Y", strtotime($get["date"]));
    echo '<tr><td><a href="http://yoururl.com/?p='.$get["post_id"].'">'.$get["guest"].'</a></td><td>'.$get["company"].'</td><td>'.$newDate.'</td></tr>';
}
echo '</table>';

```

Really appreciated doublesharp's help on this.