使用 PHP 打印 HTML 代码
Print HTML code with PHP
我的数据库中有一个数据列表,我想在 table 上显示它。我的问题是一个小细节,一切正常,除了 url link 我想放一张图片,那是行不通的。我想要的是,当用户单击图像时,浏览器重定向到一个 link,上面是我用来尝试 link url 到图像的行(图像看起来很好),我选择的 url 是 google:
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . "<a href=\"" . "https://www.google.com.br/" . "\"><img src=\"" . $img_exch_addr . "\" alt=\"" . $arr2[$cont][0] . "\"/></a></br>" . $arr2[$cont][0] . "</td>";
观察:$img_exch_addr 是我想要 link 的图片地址,$arr2[$cont][0] 是公司名称。
您可以在此处查看我用于测试的页面:http://www.bitcoinstats.info/exchange_volume.php
我显示的 php 行应该是 "Name" 列(第三个)。
我不是网络开发人员,我们将不胜感激,还有一件事,我正在使用 datatables 示例来制作此 tables,其中有很多 css 和 js 代码,我不知道它们在那里做了什么,但是,当我拿掉 class 和 id 标签时,问题仍然存在,所以我不确定这是否与此有关.
table的完整代码:
/************** Create Table *************************/
echo "<table cellspacing='0' width='100%' class='display compact' id='example'>
<thead>
<tr>
<th>World Ranking</th>
<th>Country Ranking</th>
<th>Name</th>
<th>Country</th>
<th>Pairs</th>
<th>Volume (24hr)</th>
<th>Market Share (World)</th>
<th>Market Share (Country)</th>
</tr>
</thead>
<tfoot>
<tr>
<th>World Ranking</th>
<th>Country Ranking</th>
<th>Name</th>
<th>Country</th>
<th>Pairs</th>
<th>Volume (24hr)</th>
<th>Market Share (World)</th>
<th>Market Share (Country)</th>
</tr>
</tfoot>
<tbody>";
//$aux = array($row['id'], $row['Name'], $row['Country'], $row['Type'], $row['24hrVol'],
// $row['24hrVolPosCountry'], $row['24hrVolPosWorld'], $row['24hrVolPerCountry'], $row['24hrVolPerWorld']);
$cont = 0;
while($cont<sizeof($arr2)) {
$img_addr = "/images/countries_flags/" . str_replace(" ","_",$arr2[$cont][1]) . ".png";
$img_exch_addr = "/images/exchanges_logo/" . str_replace("/","_",str_replace(" ","_",$arr2[$cont][0])) . ".png";
$url_exch = $countries_url[$arr2[$cont][0]];
if($COUNTRY==NULL or $COUNTRY===$arr2[$cont][1]){
echo "<tr>";
//echo "<a href='http://youtube.com'><img src='/images/exchanges_logo/BTCChina.png' alt='Youtube' /></a>";
if($arr2[$cont][3]<0){
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . $arr2[$cont][7] . "</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . $arr2[$cont][4] . "</td>";
echo "<td align=\"center\" style=\"font-size:14px;font-weight: bold;\"><a href=\"https://www.google.com.br/\"><img src=\"" . $img_exch_addr . "\" alt=\"" . $arr2[$cont][0] . "\"/></a></br>" . $arr2[$cont][0] . "</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . "<img src=\"" . $img_addr . "\" alt=\"" . $arr2[$cont][1] . "\" ></br>" . $arr2[$cont][1] . "</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . str_replace("BTC_", "", $arr2[$cont][2]) . "</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>-</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>-</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>-</td>";
}else{
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . $arr2[$cont][7] . "</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . $arr2[$cont][4] . "</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . "<img src=\"" . $img_exch_addr . "\" alt=\"" . $arr2[$cont][0] . "\" ></br>" . $arr2[$cont][0] . "</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . "<img src=\"" . $img_addr . "\" alt=\"" . $arr2[$cont][1] . "\" ></br>" . $arr2[$cont][1] . "</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . str_replace("BTC_", "", $arr2[$cont][2]) . "</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . round($arr2[$cont][3],4) . "</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . round($arr2[$cont][6],2) . "%</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . round($arr2[$cont][5],2) . " %</td>";
}
echo "</tr>";
}
$cont++;
}
echo " </tbody></table>";
此处连接过多 -
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . "<a href=\"" . "https://www.google.com.br/" . "\"><img src=\"" . $img_exch_addr . "\" alt=\"" . $arr2[$cont][0] . "\"/></a></br>" . $arr2[$cont][0] . "</td>";
你可以这样做 -
echo "<td align=\"center\" style=\"font-size:14px;font-weight: bold;\"><a href=\"https://www.google.com.br/\"><img src=\"" . $img_exch_addr . "\" alt=\"" . $arr2[$cont][0] . "\"/></a></br>" . $arr2[$cont][0] . "</td>";
甚至你也可以这样写
echo "<td align='center' style='font-size:14px;font-weight: bold;'><a href='https://www.google.com'><img src='" . $img_exch_addr . "' alt='" . $arr2[$cont][0] . "'/></a></br>" . $arr2[$cont][0] . "</td>"
当我检查您的 link 并查看您的源代码时,我没有看到 标记,这就是问题所在。 http://www.bitcoinstats.info/exchange_volume.php
右键单击并查看源代码
我看不出为什么这行不通(尽管它看起来确实很乱);
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . "<a href=\"" . "https://www.google.com.br/" . "\"><img src=\"" . $img_exch_addr . "\" alt=\"" . $arr2[$cont][0] . "\"/></a></br>" . $arr2[$cont][0] . "</td>";
要做的事情
- 检查您是否成功上传文件
- 检查您是否将文件上传到正确的位置。
- 检查您是否真的在正确的代码行/正确的文件上工作。
如果其他一切都正确,我看不出为什么锚点/link 无法在此代码中工作。
P.S. 你可以这样做,这样更容易阅读;
echo "<td align='center' style='font-size:14px;font-weight: bold'><a href='https://www.google.com.br'><img src='{$img_exch_addr}' alt='{$arr2[$cont][0]}'/></a></br>{$arr2[$cont][0]}</td>";
我的数据库中有一个数据列表,我想在 table 上显示它。我的问题是一个小细节,一切正常,除了 url link 我想放一张图片,那是行不通的。我想要的是,当用户单击图像时,浏览器重定向到一个 link,上面是我用来尝试 link url 到图像的行(图像看起来很好),我选择的 url 是 google:
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . "<a href=\"" . "https://www.google.com.br/" . "\"><img src=\"" . $img_exch_addr . "\" alt=\"" . $arr2[$cont][0] . "\"/></a></br>" . $arr2[$cont][0] . "</td>";
观察:$img_exch_addr 是我想要 link 的图片地址,$arr2[$cont][0] 是公司名称。
您可以在此处查看我用于测试的页面:http://www.bitcoinstats.info/exchange_volume.php 我显示的 php 行应该是 "Name" 列(第三个)。
我不是网络开发人员,我们将不胜感激,还有一件事,我正在使用 datatables 示例来制作此 tables,其中有很多 css 和 js 代码,我不知道它们在那里做了什么,但是,当我拿掉 class 和 id 标签时,问题仍然存在,所以我不确定这是否与此有关.
table的完整代码:
/************** Create Table *************************/
echo "<table cellspacing='0' width='100%' class='display compact' id='example'>
<thead>
<tr>
<th>World Ranking</th>
<th>Country Ranking</th>
<th>Name</th>
<th>Country</th>
<th>Pairs</th>
<th>Volume (24hr)</th>
<th>Market Share (World)</th>
<th>Market Share (Country)</th>
</tr>
</thead>
<tfoot>
<tr>
<th>World Ranking</th>
<th>Country Ranking</th>
<th>Name</th>
<th>Country</th>
<th>Pairs</th>
<th>Volume (24hr)</th>
<th>Market Share (World)</th>
<th>Market Share (Country)</th>
</tr>
</tfoot>
<tbody>";
//$aux = array($row['id'], $row['Name'], $row['Country'], $row['Type'], $row['24hrVol'],
// $row['24hrVolPosCountry'], $row['24hrVolPosWorld'], $row['24hrVolPerCountry'], $row['24hrVolPerWorld']);
$cont = 0;
while($cont<sizeof($arr2)) {
$img_addr = "/images/countries_flags/" . str_replace(" ","_",$arr2[$cont][1]) . ".png";
$img_exch_addr = "/images/exchanges_logo/" . str_replace("/","_",str_replace(" ","_",$arr2[$cont][0])) . ".png";
$url_exch = $countries_url[$arr2[$cont][0]];
if($COUNTRY==NULL or $COUNTRY===$arr2[$cont][1]){
echo "<tr>";
//echo "<a href='http://youtube.com'><img src='/images/exchanges_logo/BTCChina.png' alt='Youtube' /></a>";
if($arr2[$cont][3]<0){
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . $arr2[$cont][7] . "</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . $arr2[$cont][4] . "</td>";
echo "<td align=\"center\" style=\"font-size:14px;font-weight: bold;\"><a href=\"https://www.google.com.br/\"><img src=\"" . $img_exch_addr . "\" alt=\"" . $arr2[$cont][0] . "\"/></a></br>" . $arr2[$cont][0] . "</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . "<img src=\"" . $img_addr . "\" alt=\"" . $arr2[$cont][1] . "\" ></br>" . $arr2[$cont][1] . "</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . str_replace("BTC_", "", $arr2[$cont][2]) . "</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>-</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>-</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>-</td>";
}else{
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . $arr2[$cont][7] . "</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . $arr2[$cont][4] . "</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . "<img src=\"" . $img_exch_addr . "\" alt=\"" . $arr2[$cont][0] . "\" ></br>" . $arr2[$cont][0] . "</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . "<img src=\"" . $img_addr . "\" alt=\"" . $arr2[$cont][1] . "\" ></br>" . $arr2[$cont][1] . "</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . str_replace("BTC_", "", $arr2[$cont][2]) . "</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . round($arr2[$cont][3],4) . "</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . round($arr2[$cont][6],2) . "%</td>";
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . round($arr2[$cont][5],2) . " %</td>";
}
echo "</tr>";
}
$cont++;
}
echo " </tbody></table>";
此处连接过多 -
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . "<a href=\"" . "https://www.google.com.br/" . "\"><img src=\"" . $img_exch_addr . "\" alt=\"" . $arr2[$cont][0] . "\"/></a></br>" . $arr2[$cont][0] . "</td>";
你可以这样做 -
echo "<td align=\"center\" style=\"font-size:14px;font-weight: bold;\"><a href=\"https://www.google.com.br/\"><img src=\"" . $img_exch_addr . "\" alt=\"" . $arr2[$cont][0] . "\"/></a></br>" . $arr2[$cont][0] . "</td>";
甚至你也可以这样写
echo "<td align='center' style='font-size:14px;font-weight: bold;'><a href='https://www.google.com'><img src='" . $img_exch_addr . "' alt='" . $arr2[$cont][0] . "'/></a></br>" . $arr2[$cont][0] . "</td>"
当我检查您的 link 并查看您的源代码时,我没有看到 标记,这就是问题所在。 http://www.bitcoinstats.info/exchange_volume.php 右键单击并查看源代码
我看不出为什么这行不通(尽管它看起来确实很乱);
echo "<td align=\"" . "center" . "\" style='font-size:14px;font-weight: bold;'>" . "<a href=\"" . "https://www.google.com.br/" . "\"><img src=\"" . $img_exch_addr . "\" alt=\"" . $arr2[$cont][0] . "\"/></a></br>" . $arr2[$cont][0] . "</td>";
要做的事情
- 检查您是否成功上传文件
- 检查您是否将文件上传到正确的位置。
- 检查您是否真的在正确的代码行/正确的文件上工作。
如果其他一切都正确,我看不出为什么锚点/link 无法在此代码中工作。
P.S. 你可以这样做,这样更容易阅读;
echo "<td align='center' style='font-size:14px;font-weight: bold'><a href='https://www.google.com.br'><img src='{$img_exch_addr}' alt='{$arr2[$cont][0]}'/></a></br>{$arr2[$cont][0]}</td>";