通过PHP从MySql传递URL

时间:2014-04-04 21:34:09

标签: php mysql

我正在尝试研究如何传递存储在MySQL数据库中的URL并将其附加到图像中。 我到目前为止的脚本是:

<?php
$con = mysqli_connect("**********","*********","******","********");

// Check connection
if (mysqli_connect_errno()) {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$selectedOption = $_POST["mySelect"];

$result = mysqli_query($con, 
   sprintf("SELECT * FROM `SouthYorkshire` WHERE  `EstProv` = '%s'",
      preg_replace("/[^A-Za-z ]/", '', $selectedOption)
   )
); // pattern based on your html select options

echo "<div id=\"Results\">";

while($row = mysqli_fetch_array($result)) {
   echo "<div class=\"ClubName\">";
   echo $row['EstName'];
   echo "</div><br>";
   echo "<div class=\"Location\">";
   echo $row['EstAddress2'];
   echo "</div>";
   echo "<br>";
   echo "<div id=\"website\"><img src=\"photos/visit-website-button.png\" width=\"75\" height=\"25\" /></div>";
}
echo date("Y") . " " ."Search is Powered by PHP.";
echo "</div>";

mysqli_close($con);

我想改变的是: echo "<div id=\"website\"><img src=\"photos/visit-website-button.png\" width=\"75\" height=\"25\" /></div>"

我尝试将上述内容与$row['EstWebsite']

一起使用

但是没有任何成功,任何建议都会很棒。

非常感谢

2 个答案:

答案 0 :(得分:0)

您可以使用以下内容:

echo "<div id=\"website\"><img src=\"" . $row['ImageColumnName'] ."\" width=\"75\" height=\"25\" /></div>";

答案 1 :(得分:0)

网址来自何处并不重要,最后它只是一串数据,而您只是要用它构建一些HTML,所以

echo '<div id="website"><a href="' . $url . '"><img blah blah blah></a>";
                        ^^^^^^^^^^^^^^^^^^^^^^^-add this           ^^^^--add this