开发者

How do I make a url field from mySQL appear as a link in a html table?

I have a table linked to my mySQL database.

I have a particular field that contains a url. The url appears in the table correctly, but does not work as a link.

Can I make the url appear as a link?

The field is "pdf_link"

Here is my code:

<?php
$db 开发者_运维问答= new mysqli("localhost", "XXXXX", "XXXXXX", "XXXXXXXX");
$query = "SELECT part_no, description, count, size, pdf_link,  min, max,  current FROM folding_cartons LIMIT 0,50";

$result = $db->query($query, MYSQLI_STORE_RESULT);

$o = '<table id="tablesorter-demo" class="tablesorter" border="0" cellpadding="0"
cellspacing="1"><thead><tr><th>Part Number</th><th>Description</th><th>Count</th>
<th>Size</th><th>PDF Link</th><th>Min</th><th>Max</th><th>Current</th></tr></thead>
<tbody>';

while(list($part_no, $description, $count, $size, $pdf_link, $min, $max, $current) =
$result->fetch_row()) {
   $o .= '<tr><td>'.$part_no.'</td><td>'.$description.'</td><td>'.$count.'</td>
   <td>'.$size.'</td><td>'.$pdf_link.'</td><td>'.$min.'</td><td>'.$max.'</td>
   <td>'.$current.'</td></tr>';
}
$o .= '</tbody></table>';
echo $o;
?>


You aren't using the link markup. Change the

'</td><td>'.$pdf_link.'</td><td>'

part to

'</td><td><a href="'.$pdf_link.'">'.$pdf_link.'</a></td><td>'


  <?php
  $db = new mysqli("localhost", "XXXXX", "XXXXXX", "XXXXXXXX");
  $query = "SELECT part_no, description, count, size, pdf_link,  min, max,  current FROM 
  folding_cartons LIMIT 0,50";

  $result = $db->query($query, MYSQLI_STORE_RESULT);

  $o = '<table id="tablesorter-demo" class="tablesorter" border="0" cellpadding="0"
  cellspacing="1"><thead><tr><th>Part Number</th><th>Description</th><th>Count</th>
  <th>Size</th><th>PDF Link</th><th>Min</th><th>Max</th><th>Current</th></tr></thead>
  <tbody>';

  while(list($part_no, $description, $count, $size, $pdf_link, $min, $max, $current) = 
  $result->fetch_row()) {
  $o .= '<tr><td>'.$part_no.'</td><td>'.$description.'</td><td>'.$count.'</td>
  <td>'.$size.'</td><td><a href="'.$pdf_link.'">'.$pdf_link.'</a></td><td>'.$min.'</td><td>'.$max.'</td>
  <td>'.$current.'</td></tr>';
  } 
  $o .= '</tbody></table>';
  echo $o;
  ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜