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
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>';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.