Help to configure href

Asked

Viewed 34 times

0

I have this code below,

<?php include "conexao.php"; ?>
<div id="produtos-content">
<!-- Listando os Categorias -->
    <?php
    $nome_cat = $_POST['nome_cat'];
    $img_cat = $_POST['img_cat'];
    $query_categoria = mysql_query("SELECT * FROM categoria");
    while($res = mysql_fetch_array($query_categoria)){
    ?>
   <div style="float:left; width:112px; height:133px; padding:2px 10px;" id="cats-list">
            <a class="cat-link" href="javascript:;" title="<?php echo $res['nome_cat']; ?>">
                <img style="position:relative; top:50%; transform:translateY(-50%);"
                src="img_cate/<?php echo $res['img_cat']; ?>" width="100"
                title="<?php echo $res['nome_cat']; ?>" />
            </a>
            <div style="background:#2f2140; ; width:880px;z-index:999;border-radius:25px;" class="single-cat">
                <h1 align="center" style="width:830px; margin-top:-40px;"><?php echo $res['nome_cat']; ?></h1>
                <div style="margin-left:357px;width:50px;" class="cat-links">
                    <a class="close-btn" href="javascript:;" title="Voltar">
                        <img src="img/fechar.jpg" />
                    </a>
                </div>
    <?php
    $codigo = $_POST['codigo'];
    $img_prod = $_POST['img_prod'];
    $titulo = $_POST['titulo'];
    $descricao = $_POST['descricao'];
    $nome_cat = $_POST['nome_cat'];
    $query_produtos = mysql_query("SELECT * FROM produtos") or die(mysql_error());
    while($res = mysql_fetch_array($query_produtos)){
        ?>
        <div style="float:left; width:112px; height:133px; padding:2px 10px;" id="songs-list">
        <a class="song-link" href="javascript:;" title="">
            <img style="position:relative; top:50%; transform:translateY(-50%);" src="img_prod/<?php echo $res['img_prod']; ?>" width="100" title="<?php echo $res['titulo']; ?>" />
            </a>

            <div style=" margin-top:120px;z-index:999;border-bottom-right-radius:25px;border-top-right-radius:25px;" class="single-song">
            <div style="width:50px;margin-left:300px;" class="song-links">
                <a class="close-btn" href="javascript:;" title="Voltar">
                    <img src="img/fechar.jpg" />
                </a>
                    <div class="song-sides">
                        <img style="margin:40px 0 0 -142px;" src="img_prod/<?php echo $res['img_prod']; ?>" width="369" />
                    </div>
                </div>
                <h1> <?php echo $res['titulo']; ?> </h1>
                <div class="entry" style="overflow-y: hidden; padding: 0px; width: 100px;">
                <p style="font-family:Verdana, Geneva, sans-serif; size:14px; font-weight:bold; color:#ccc;">
                <?php echo nl2br($res['descricao']); ?>
                </p>
                <div class="jspContainer" style="width: 100px; height: auto;">
                <div class="jspPane" style="padding: 0px; top: 0px; width: 100px;">
                </div></div>
                </div>
                <span class="song-sides left-side"></span>
            </div>
        </div>
    <?php } ?>
            </div>
        </div>
        <?php
        }
        ?>
    </div>
</div>

<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery(".single-cat .close-btn").click(function(){
        jQuery(this).parent().parent().fadeOut();
    });

    jQuery(".single-song .close-btn").click(function(){
        jQuery(this).parent().parent().fadeOut();
    });
 });
 </script>

and needing help from friends to make href="javascript:;" from DIV id="Cats-list", bring only the products referring to the selected Category, opening them in DIV id="Songs-list".

At the moment by clicking on any of the two registered categories, brings me all products registered in the table "PRODUCTS".

I’ve tried using the code below (which works perfect in PHP),

<?php
include "conexao.php";
$nome_cat = $_GET['nome_cat'];
$query_produtos = mysql_query("SELECT * FROM produtos WHERE nome_cat = '$nome_cat'") or die(mysql_error());
while($res = mysql_fetch_array($query_produtos)){

$codigo = $_POST['codigo'];
$img_prod = $_POST['img_prod'];
$titulo = $_POST['titulo'];
$descricao = $_POST['descricao'];
$nome_cat = $_POST['nome_cat'];
?>

to search only the products referring to the category selected and sent via GET in DIV id="Songs-list", but without success.

I believe I have to create an event for this Function, but I am very lay in Javascript, and I count on the help of friends if possible.

Problem solved with the code below:

With the help of our friend @Givanildo R. de Oliveira, we were able to solve the problem and bring only the products related to the selected category.

Down with the working code:

<?php include "conexao.php"; ?>

<div id="produtos" class="sections full-width-wrapper bg_4">
    <div class="centered-wrapper">

        <div class="section-header">
            <?php include 'menu_pags.php';?>            
        </div>

<div id="produtos-content">

    <!-- Listando os Categorias -->
    <?php
    $nome_cat = $_POST['nome_cat'];
    $img_cat = $_POST['img_cat'];
    $query_categoria = mysql_query("SELECT * FROM categoria");
    while($res = mysql_fetch_array($query_categoria)){
    ?>
    <div style="float:left; width:112px; height:133px; padding:2px 10px;" id="cats-list">
        <a class="cat-link" href="?nome_cat=<?php echo $res['nome_cat']; ?>#produtos" title="<?php echo $res['nome_cat']; ?>">
        <img style="position:relative; top:50%; transform:translateY(-50%);"
            src="img_cate/<?php echo $res['img_cat']; ?>" width="100"
            title="<?php echo $res['nome_cat']; ?>" />
        </a>
        <div style="background:#2f2140; ; width:880px;z-index:999;border-radius:25px; <?php echo $res['nome_cat']==$_GET['nome_cat'] ? 'display:block;' : ''; ?>" class="single-cat">
            <h1 align="center" style="width:830px; margin-top:-40px;"><?php echo $res['nome_cat']; ?></h1>
            <div style="margin-left:357px;width:50px;" class="cat-links">
                <a class="close-btn" href="javascript:;" title="Voltar">
                    <img src="img/fechar.jpg" />
                </a>
            </div>

<!-- Listando os produtos -->
<?php
$nome_cat = $_GET['nome_cat'];
$query_produtos = mysql_query("SELECT * FROM produtos WHERE nome_cat = '$nome_cat'") or die(mysql_error());
while($res = mysql_fetch_array($query_produtos)){

$codigo = $_POST['codigo'];
$img_prod = $_POST['img_prod'];
$titulo = $_POST['titulo'];
$descricao = $_POST['descricao'];
$nome_cat = $_POST['nome_cat'];
?>

    <div style="float:left; width:112px; height:133px; padding:2px 10px;" id="songs-list">
            <a class="song-link" href="javascript:;" title="">
            <img style="position:relative; top:50%; transform:translateY(-50%);" src="img_prod/<?php echo $res['img_prod']; ?>" width="100" title="<?php echo $res['titulo']; ?>" /></a>

        <div style=" margin-top:120px;z-index:999;border-bottom-right-radius:25px;border-top-right-radius:25px;" class="single-song">
            <div style="width:50px;margin-left:300px;" class="song-links">
            <a class="close-btn" href="javascript:;" title="Voltar">
                <img src="img/fechar.jpg" />
            </a>
                <div class="song-sides">
                    <img style="margin:40px 0 0 -142px;" src="img_prod/<?php echo $res['img_prod']; ?>" width="369" />
                </div>
            </div>

            <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />

            <h1> <?php echo $res['titulo']; ?> </h1>
            <div class="entry" style="overflow-y: hidden; padding: 0px; width: 100px;">
            <p style="font-family:Verdana, Geneva, sans-serif; size:14px; font-weight:bold; color:#ccc;">
            <?php echo nl2br($res['descricao']); ?>
            </p>
            <div class="jspContainer" style="width: 100px; height: auto;">
            <div class="jspPane" style="padding: 0px; top: 0px; width: 100px;">
            </div></div></div>
            <span class="song-sides left-side"></span>
        </div>
    </div>
<?php
}
?>

        </div>
    </div>
    <?php
    }
    ?>
</div>

</div></div></div>

I hope I can help other users with the same problem.

  • OK @Bacco, really I’ve asked a question on this subject, but I did not get an answer that would solve or even help me solve the problem, so if you can answer it I would be very grateful.

  • 1

    You’re actually doing a lot of them. In order for the community to be able to help you, it is important that you pay more attention to the comments and questions that other colleagues ask to better understand your problem. Asking multiple questions won’t help you, focusing on crafting one better gives you a better chance of success. It is suggested to stick less to the code you already have, and explain better in the questions the effect to be obtained (perhaps with examples) not to fall into a XY problem. The code is mere consequence.

No answers

Browser other questions tagged

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