Jump to content

Hyperlink table column??


mapmedia

Recommended Posts

I am able to display all fields of my database in a html table YAY! 

 

but

 

I would like to make the last column hyper-linked to the url stored in it.

 

What do I need to do this?  Can I alter my existing code or re-do it?

.............

$sqlCommand = "SELECT * FROM COUNTIES where state = '$id' LIMIT 0, 10";

$result = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());

 

$fields_num = mysqli_num_fields($result);

 

echo "<h1>Table</h1>";

echo "<table border='1'><tr>";

// printing table headers

for($i=0; $i<$fields_num; $i++)

{

    $field = mysqli_fetch_field($result);

    echo "<td>{$field->name}</td>";

}

echo "</tr>\n";

// printing table rows

while($row = mysqli_fetch_row($result))

{

    echo "<tr>";

 

    // $row is array... foreach( .. ) puts every element

    // of $row to $cell variable

    foreach($row as $cell)

        echo "<td>$cell</td>";

 

    echo "</tr>\n";

}

mysqli_free_result($result);

Link to comment
https://forums.phpfreaks.com/topic/203374-hyperlink-table-column/
Share on other sites

function urlify($value) {
  return 'http' === substr($value, 0, 4) ? '<a href="' . $value . '">' . $value . '</a>' : $value;
}

 

Use like:

 

echo '<td>', urlify($cell), '</td>';

 

Is this something like PHPMyAdmin you are creating if so you may be better off using a plugin system like:

 

function table_cell_helper($value) {
  $value = call_plugins('counties_table_cell', $value);
}

function call_plugins($identifier, $value) {
  $plugins = get_plugins($identifier);
  foreach ($plugins as $plugin) {
    $value = call_user_func($plugin, $value);
  }
  return $value;
}

 

Use like:

 

echo '<td>', table_cell_helper($cell), '</td>';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.