1

For my project I created a search engine to search some books from the database. I also made a bookpage where you can find the whole information of the book and were you can react. But now I'm having trouble with linking the two with each other. In my code you can see the code that I am using to show the information in the search page but the title has to be a LINK to his specified bookpage. How can I fix it? Now I can only see the specified bookpage with f.e. book.php?bid=1 (book id = 1).

if ($numrows > 0) {
    while ($row = mysql_fetch_assoc($query)) {
        $id = $row['book_id'];
        $title = $row['book_title'];
        $author = $row['book_author'];
        $description = $row['book_description'];
        $keywords = $row['book_keywords'];
        $cover = $row['book_cover']; 
        $year = $row['book_year'];
        $feedback_search = "Results found for \"<b>$k</b>\"";
        $feedback_search = "<h1>$cover $title <span>($year)</span></h1><h2><h2><b>Author:</b> $author</h1> <br/> <p>$description</p></h2><hr /> ";
        echo $feedback_search;

    }
} 
else {

    $feedback_search = "<h1>No results found for \"<b>$k</b>\"</h1>";
    echo $feedback_search;

}

// disconnect db
mysql_close();
4

2 回答 2

0

您可以使用锚标记( <a>) 在 html 代码中创建链接:

$feedback_search = "<h1>$cover <a href='book.php?bid=$id'>$title</a>...

基本上,嵌入标签并将href属性设置为书籍信息页面。我还嵌入了$id上面的值,所以它知道要显示哪个书的 ID。

另请注意,对于引号内的引号,我使用了单引号 ( ') 而不是双引号。另一种解决方案是转义内部引号<a href=\"...

于 2012-05-18T21:52:42.307 回答
0

If I understand correctly, just add an anchor around the title, which links to book.php with the book's ID passed to it, e.g:

 $feedback_search = "<h1>$cover <a href=\"book.php/?bid=$id\">$title</a> <span>($year)</span></h1><h2><h2><b>Author:</b> $author</h1> <br/> <p>$description</p></h2><hr /> ";
于 2012-05-18T21:53:57.707 回答