Open Mysql data on another page

Asked

Viewed 91 times

0

I started working on Mysql a little while ago and I have a little problem and I don’t know how to fix it. If anyone can help me I appreciate it. I have a book site that shows the photo of the book and below the photo, has information. Clicking on information opens a new page with the information only for that book. But that’s the problem... The way I’m trying to do, it shows the information of all the books registered in the bank and I don’t know how to show only the book that the person wants to see.

On the.php books page, shows the book photo:

            <div class="col-md-3 col-sm-6 col-xs-12">
                <div class="gallery-item">
                    <div class="gallery">
                        <div class="list-group">
                            <form class="form-inline" action="livros.php" method="post">
                            <div class="form-group input-group">
                                <span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
                                <input name="titulo" id="titulo" placeholder="Pesquisar por Título..." type="text" class="form-control">
                            </div>
                            </form>
                            <br>
                            <a class="list-group-item active"><i class="fa fa-key"></i> <span>GÊNEROS</span></a>
                            <?php do {  ?>
                            <a class="list-group-item" href="livros.php?genero=<?php echo utf8_encode($linhas_menu['id']); ?>"> 
                    <?php echo $linhas_menu['genero']; ?></a>

                    <?php } while ($linhas_menu = mysql_fetch_assoc($resultado_menu));  ?>

                        </div>
                    </div>

                </div>
            </div>


             <?php do {  ?>
            <div class="col-md-3 col-sm-6 col-xs-12">
                <div class="gallery-item">
                    <div class="gallery">
                        <img src="Admin/app/webroot/files/livro/imagem/<?php echo $linhas['imagem_dir']; ?>/<?php echo $linhas['imagem']; ?>">
                        <a href="download.php#features" target="_blank"><h6>Informação</h6></a>

                    </div>

                </div>

            </div>
            <?php } while ($linhas = mysql_fetch_assoc($resultado));  ?>

    </div> <!-- /container -->

</section>

Already on the download page.php, it would show the information only of that book:

        <!-- Sections -->
    <section id="features" class="sections lightbg">

        <div class="container text-center">

            <div class="heading-content">
                <h3>Informação</h3>
            </div>

            <!-- Example row of columns -->
            <div class="row">
                <?php do{ ?>
                <div class="col-md-4 col-sm-6 col-xs-12">

                    <div class="features-content">
                        <img src="Admin/app/webroot/files/livro/imagem/<?php echo $linhas_livro['imagem_dir']; ?>/<?php echo $linhas_livro['imagem']; ?>">
                    </div>
                </div>


                <div class="col-md-8 col-sm-6 col-xs-12">
                    <div class="features-content">

                        <table class="table table-bordered table-dark">
                          <thead>
                            <tr>
                              <th scope="row"><h4>Autor:</h4></th>
                              <td><?php echo $linhas_livro['autor']; ?></td>
                            </tr>
                          </thead>
                          <tbody>
                            <tr>
                              <th scope="row"><h4>Título:</h4></th>
                              <td><?php echo $linhas_livro['titulo']; ?></td>
                            </tr>
                            <tr>
                              <th scope="row"><h4>Gênero:</h4></th>
                              <td><?php echo $linhas_livro['genero']; ?></td>
                            </tr>
                            <tr>
                              <th scope="row"><h4>Sinopse:</h4></th>
                              <td colspan="2"><?php echo utf8_encode($linhas_livro['sinopse']); ?></td>
                            </tr>
                            <tr>
                              <td colspan="2">╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬</td>
                            </tr>
                            <tr>
                              <th class="download-tabela" scope="row"><h4>Download:</h4></th>
                              <td colspan="2"><a href="Admin/app/webroot/files/livro/arquivo/<?php echo $linhas_livro['arquivo_dir']; ?>/<?php echo $linhas_livro['arquivo']; ?>" target="_blank"><i class="fa fa-download"></i></a></td>
                            </tr>
                          </tbody>
                          <?php } while ($linhas_livro = mysql_fetch_assoc($resultado_livro));  ?>
                        </table>

                    </div>
                </div>
            </div>
        </div> <!-- /container -->

    </section>

Is there any way to get the book information open from his id? For example, click on the Harry Potter book that in the database is id 3, and open only the information from that book?

I’d really appreciate it if someone could help me. Thank you.

1 answer

2


You need to put in href of each link, page livros.php, the id of the book to be opened (display information). And receive this id on the page download.php. Something like

Page livros.php

<a href="download.php?idlivro=3" target="_blank">

Page download.php

<?php
$id = $_GET['idlivro'];
$resultado = mysql_query('SELECT * FROM livros WHERE id = ' . $id, $link_bd);
....
....
?>

Applying to your code

php books page.

<?php do {  ?>
<div class="col-md-3 col-sm-6 col-xs-12">
    <div class="gallery-item">
        <div class="gallery">
        <img src="Admin/app/webroot/files/livro/imagem/<?php echo $linhas['imagem_dir']; ?>/<?php echo $linhas['imagem']; ?>">
        <a href="download.php?idlivro=<?php echo $linhas['id'] ?>" target="_blank"><h6>Informação</h6></a>
        </div>
    </div>
</div>
<?php } while ($linhas = mysql_fetch_assoc($resultado));  ?>

Page download.php

<?php
$id = $_GET['idlivro'];
$resultado_livro = mysql_query('SELECT * FROM livros WHERE id = ' . $id, $link_bd);
....
....
?>

Improvements

  • Thanks for the help. I will try to implement here on my site :)

  • Unfortunately I couldn’t pull the book by id. I did as you mentioned: <? php $id = $_GET['idlivro']; $resultado_livro = mysql_query('SELECT * FROM books WHERE id = ' . $id, $Conn); $linhas_livro = mysql_fetch_assoc($resultado_livro); ? > <? php echo $linhas_book['category']; ? > But when I click to open another book, it is always the same photo and the same information in all, does not change. I don’t know what else to do.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.