php - mysqli_fetch_array using a foreach loop -
ive got pretty basic table named 'customers' 4 columns:
id (primary auto increment)
businessname
contactname
contactemail
i call with:
$result = mysqli_query($con, "select * customers");
and using mysqli_fetch_array display on page foreach loop:
while ($row = mysqli_fetch_array($result, mysqli_assoc)) { echo "<tr>"; foreach ($row $value) { echo "<td>" . $value . "</td>"; } echo "<td><a href='updateform.php?id=" . $row['id'] . "'>edit</a></td>"; echo "</tr>"; }
which gives array like:
array ( [id] => 1 [businessname] => microsoft [contactname] => bill gates [contactemail] => bill@microsoft.com ) array ( [id] => 2 [businessname] => amazon [contactname] => jeff bezos [contactemail] => jeff@amazon.com )
is possible display results differently based on column (technically position in array) in? make
a href="mailto:bill@microsoft.com"
link when gets contactemail.
if wanted display 1 key or value instead of using foreach?
doesn't seem possible call
$row['contactemail']
in foreach loop confuses me since below able create link
$row['id']
if has ideas how this, or if there better way displaying information, i'm open suggestions, i'm not @ programming, php.
yes! can add this:
while ($row = mysqli_fetch_array($result, mysqli_assoc)) { echo "<tr>"; foreach ($row $key => $value) { if($key == "contactemail"){ $mailurl = "mailto:".$value; echo "<td><a href=".$mailurl.">".$value."</a>"; } else{ echo "<td>" . $value . "</td>"; } } echo "<td><a href='updateform.php?id=" . $row['id'] . "'>edit</a></td>"; echo "</tr>"; }
Comments
Post a Comment