doutenggu4070 2017-02-07 16:06
浏览 72
已采纳

添加我的PHP echo的链接

So I have a PHP script that fetches the 'names' of some ID's on my DB. It then displays these 'names' on my index page as a user begins to search in the search bar. What I just can't seem to get working is the href link. I wish the 'names' that appear, hyperlink to their given page. Example: I search for The Beatles in the search bar 'The Beatles' is displayed on my search result and when I click 'The Beatles' link it takes me to www.mywebsite.com/'thebeatles'.html and it gives me thebealtes.html based on the 'names' that was fetched by my PHP script.

$host = "localhost";
$user = "root";
$password = "";
$db = "images";

$conn=mysqli_connect($host, $user, $password, $db);

if(!empty($_GET['q'])){

    $q = $_GET['q'];
    $query = "SELECT * FROM names WHERE names like '%$q%'";
    $result = mysqli_query($conn, $query);
    while($row = mysqli_fetch_assoc($result)){

        $name = $row['names'];

        echo '<a href=..........><div class="searchoutput">'.$name.'</a><br><div class="col-md-8"></div></div>';

    }
}

If someone could help me figure out what I put where I have put href=........ that would be great.

  • 写回答

2条回答 默认 最新

  • douzhao7014 2017-02-07 16:16
    关注
    $link = str_replace(' ', '', strtolower($name));
    echo '<a href="'.$link.'html"><div class="searchoutput">'.$name.'</a><br><div class="col-md-8"></div></div>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应