简体   繁体   中英

echo link on mysql variable depending on

showList.php

<?php

  while($row = mysqli_fetch_assoc($result)) {
    echo $row['title']; 
    echo $row['author'];
  }

?>

So basically this is a book search sorted by genre, which will show a list of books matching the desired genre.

What I want from there, is that eg the title or a button is clickable to reach viewBook.php, which in turn shows the specific book the user has chosen.

I've figured that I should somehow fit $_POST/$_GET in there like on the page previous to showList.php to be able to pick ut up on viewFilm.php, but I haven't manage to pull it off. Combining PHP and HTML is proving harder than I'd have thought, never dealt with a webbased language before and not two simultaneously either.

Any help/tips/links to guides is appreciated, thanks in advance.

  while($row = mysqli_fetch_assoc($result)) {
    $str = '<a  href="viewBook.php?book_id='.$row['id'].'">';
    $str .= $row['title'].' ('.$row['author'].')';
    $str .= '</a><br />';
    echo $str;
  }

on your viewBook.php script you can get book_id from $_GET

or if you have no book_id in your $row:

while($row = mysqli_fetch_assoc($result)) {
        $str = '<a  href="viewBook.php?book_title='.$row['title'].'">';
        $str .= $row['title'].' ('.$row['author'].')';
        $str .= '</a><br />';
        echo $str;
      }

:-)

hope it is helpful for you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM