mapmedia Posted May 30, 2010 Share Posted May 30, 2010 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); Quote Link to comment Share on other sites More sharing options...
pornophobic Posted May 30, 2010 Share Posted May 30, 2010 for the link you would have to specify it. This example is assuming you have say three fields in a table; id, name, link. echo '<td><a href="' . $row['link'] . '">' . $row['name'] . '</a>'; Hope that was any help. Quote Link to comment Share on other sites More sharing options...
mapmedia Posted May 31, 2010 Author Share Posted May 31, 2010 eh...what part of my code would I replace with the helpful snippet you provided? Trying to get this baby working Quote Link to comment Share on other sites More sharing options...
ignace Posted May 31, 2010 Share Posted May 31, 2010 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>'; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.