我的数据库中有一个数据列表,我希望在表格中显示该数据。我的问题是一个小细节,一切正常,除了我想要放在图像上的网址链接,这是行不通的。我想要的是,当用户点击图片时,浏览器会重定向到一个链接,上面是我尝试将网址链接到图片的线条(图片显示正常),我选择的网址是谷歌:
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是我想要链接的图像的地址,$ arr2 [$ cont] [0]是公司的名称。
您可以在此处查看我用于测试的页面:http://www.bitcoinstats.info/exchange_volume.php 我展示的php专栏应该是专栏&#34; Name&#34; (第三个)。
我不是网络开发者,任何帮助都会受到赞赏,还有一件事,我使用datatables示例制作这个表,我有很多css和js代码我不知道他们在那里做了什么,但是,当我把课程和id标签拿走时,问题仍然存在,所以我不确定这是否有任何关系。
表格的整个代码:
/************** 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>";
答案 0 :(得分:3)
这里连接太多了 -
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>";
答案 1 :(得分:1)
我认为没有理由说这不起作用(尽管看起来真的很乱);
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>";
要做的事
如果其他一切都正确,我认为没有理由说锚/链接在这段代码中不起作用。
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>";
答案 2 :(得分:0)
甚至你可以写这样的
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>"
当我检查你的链接,并查看你的代码我看到没有&lt; a&gt;标签,这是问题所在。 http://www.bitcoinstats.info/exchange_volume.php 右键单击并查看源