0

我正在创建一个 PHP 页面,该页面打印出我拥有的肉类包装的整个数据库。我正在按形状(矩形、椭圆形、方形、插入)的顺序打印数据库的结果。我可以很高兴地让数据库打印出结果,但我想要对其中一列做的是更改打印到 HTML 链接中的结果。

此列是“Imagename”,它打印存储在服务器上的 JPEG 的名称。我想要它,这样当“Imagename”的结果在侧面打印 JPEG 时,它不是文本,而是指向显示图片供用户查看的新选项卡的链接。

这是我当前的 PHP,它循环通过数据库在表中打印:

<?php

$con = mysql_connect("localhost", "horizon1", "");
mysql_select_db("horizon1_delyn", $con);

if ( ! $con)
{
  die("Could not connect: " . mysql_error());
}

$rectangular = mysql_query("SELECT toolcode, description, traysize, imagename FROM range WHERE trayshape ='rectangular' ORDER BY traysize");
$oval        = mysql_query("SELECT toolcode, description, traysize, imagename FROM range WHERE trayshape ='oval' ORDER BY traysize");
$square      = mysql_query("SELECT toolcode, description, traysize, imagename FROM range WHERE trayshape ='square' ORDER BY traysize");
$insert      = mysql_query("SELECT toolcode, description, traysize, imagename FROM range WHERE trayshape ='insert' ORDER BY traysize");

$fields_num = mysql_num_fields($rectangular);

echo "<table width='97%' border='0' cellspacing='0' cellpadding='0'><tr>";


//*RECTANGULAR*//

for ($i = 0; $i < $fields_num; $i++)
{
  $field = mysql_fetch_field($rectangular);
  echo "<td bgcolor='#E8CF24' style='font-family: arial;font-size: 12px;'>{$field->name}</td>";
}

echo "</tr>\n";

while ($row = mysql_fetch_row($rectangular))
{
  echo "<tr>";

  foreach ($row as $cell)
    echo "<td style='font-family: arial;font-size:12px'>$cell</td>";
  echo "</tr>\n";
}
mysql_free_result($rectangular);


//* OVAL *// 

for ($i = 0; $i < $fields_num; $i++)
{
  $field = mysql_fetch_field($oval);
  echo "<td bgcolor='#E8CF24' style='font-family: arial;font-size: 12px'>{$field->name}</td>";
}

echo "</tr>\n";

while ($row = mysql_fetch_row($oval))
{
  echo "<tr>";

  foreach ($row as $cell)
    echo "<td style='font-family: arial;font-size:12px'>$cell</td>";

  echo "</tr>\n";
}
mysql_free_result($oval);


//* SQUARE *// 

for ($i = 0; $i < $fields_num; $i++)
{
  $field = mysql_fetch_field($square);
  echo "<td bgcolor='#E8CF24' style='font-family: arial;font-size: 12px'>{$field->name}</td>";
}

echo "</tr>\n";

while ($row = mysql_fetch_row($square))
{
  echo "<tr>";

  foreach ($row as $cell)
    echo "<td style='font-family: arial;font-size:12px'>$cell</td>";

  echo "</tr>\n";
}
mysql_free_result($square);


//* INSERT *// 

for ($i = 0; $i < $fields_num; $i++)
{
  $field = mysql_fetch_field($insert);
  echo "<td bgcolor='#E8CF24' style='font-family: arial;font-size: 12px'>{$field->name}</td>";
}

echo "</tr>\n";

while ($row = mysql_fetch_row($insert))
{
  echo "<tr>";

  foreach ($row as $cell)
    echo "<td style='font-family: arial;font-size:12px'>$cell</td>";

  echo "</tr>\n";
}
mysql_free_result($insert);

?>

有谁知道我如何在某种意义上隔离“Imagename”列以使图像可点击?谢谢你的帮助?

4

1 回答 1

1

首先,他们会因为你不逃跑而将你撕成碎片,但我会让其他人为此责备你。

在您一口气输出表格中的所有内容的那一刻,您需要将其拆分,因此而不是

echo "<td style='font-family: arial; font-size: 12px;'>{$cell}</td>";

你会想要类似的东西

echo '<td style="font-family: arial;font-size:12px">' . $cell['toolcode'] . '<a href=' . $cell['imagename'] . ' target="_blank">' . $cell['imagename'] . '</a></td>';

您需要单独回显这些值,然后<a>在超链接周围加上一个标签,并带有一个 href

于 2012-10-31T09:08:07.363 回答