I have a database query set up that returns an array. I then cycle through the rows in a foreach statement that wraps each value in a <td> tag to output it to a table.
It works really great, but now I need to access two of the values and add some info to them. The first field returned is an image filename and I want to wrap it in an image tag that also concatenates the image path location to the value. All the images are stored in the same location, so basically I want to take the first value form the array and add the path to where the images are and wrap the whole thing in an <img> tag.
The other field I need to modify is the last value in the array which is actually an email address. For that field I want to make them an active email link so I need to wrap an <a>href=mailto: </a> tag around the value.
How should I modify this code so I could add the necessary tags to these items?
Here is the code I am running:
$query = "Select
member_image as 'Image',
member_name as 'Name',
city as 'City',
phone as 'Phone',
email as 'Email'
FROM directory";
//connect to database
$conn=db_connect();
//call function do_query to run the query and output the table
do_query($conn, $querey);
The functions called are as follows:
function db_connect()
{
[INDENT]$conn = new mysqli("localhost", "username", "password", "databasename");
[/INDENT]
}
function do_query($conn, $query);
{
[INDENT]
$result = mysqli_query($conn, $query);
WHILE ($row = mysqli_fetch_assoc($result))
{
If (!$heading) //only do if header row hasn't been output yet
{$heading = TRUE; //so we only do it once
echo "<table>\n<tr<>\n";
foreach ($row as $key => $val)
{
echo "<th>$key</th>";
}
echo "</tr>\n";
}
echo "<tr>";
foreach ($row as $val)
{
echo "<td> $val </td>";
}
echo "</tr>\n";
} //close the while
echo "</table>\n";
[/INDENT]
}