我想制作一个从服务器上的MySQL数据库表(www.domain.com)获取结果的PHP页面。动态地从分表中的URL字符串链接到HTML/PHP页面
该表具有以下字段:
ID (ie: 1) Date (ie: 2014-12-06) Text (ie: Guns 'n Roses) URL (ie: https://www.youtube.com/watch?v=xxxxxxx) Link (ie: Watch on YouTube)
URL在文本链接到网页锚定。
我的查询很简单直接:简单的select * from table
。当运行在屏幕上,PHP页打印下表:
2014-12-06 --- Guns 'n Roses --- Watch on YouTube
,其中,通过点击“在YouTube上观看”,实际地址就变成了:
www.domain.com/https://www.youtube.com/watch?v=xxxxxxx
我怎样才能摆脱服务器的根,并有一个工作链接?
的代码是:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div id="youtube">
<?php
require "parameters.php";
$con = mysqli_connect($host,$user,$password,$db);
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT Date, Text, URL, Link FROM $db.$table_10 ORDER BY date desc");
echo "<table>";
echo "<tr><th>Date</th><th>Text</th><th>Link</th></tr>";
echo "<tr><td></br></td></tr>";
while($row = mysqli_fetch_array($result)) {
$safe_url = mysqli_real_escape_string($con, $row['URL']);
echo "<tr>";
echo "<td>" . $row['Date'] . "  </td>";
echo "<td>" . $row['Text'] . "</td>";
echo "<td><a href=" . $safe_url . " " . "target="."_blank".">" . $row['Link'] . "</a></td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
</div>
</body>
</html>
感谢您的回复和帮助我!
请准确显示转储'SELECT'结果的代码。 – angelsl 2014-12-06 17:40:05
您需要向我们展示您的PHP/HTML如何检索数据。这不是关于“如何摆脱”,而是关于使用正确的语法。 – 2014-12-06 17:41:03
在我看来,问题标题是错误的 – vladkras 2014-12-06 17:43:28