How to adapt Javascript href to access a php page?

Asked

Viewed 4,809 times

0

Hello, I’m trying to get Javascript href to bring the content of another php page into your source page...

Well I don’t know if I could explain myself to the point where my friends understand what I need...

But come on...

I have this code below

    <ul id="songs-list">
    <li>
        <a class="song-link" href="javascript:;" title=""><strong>01</strong> Titulo 01 </a>
        <div class="single-song">
        <div class="song-links">
        <a class="close-btn" href="javascript:;" title="Voltar"></a>
            <div class="song-links-img">
                <img style="margin:-50px 0 0 -50px;" src="fancybox/img/escada.jpg" width="369" />
            </div>
        </div>
        <h1><strong>01</strong> Descrição do Produto 01 </h1>
        <div class="entry" style="overflow-y: hidden; padding: 0px; width: 100px;">
        <div class="jspContainer" style="width: 100px; height: 530px;">
        <div class="jspPane" style="padding: 0px; top: 0px; width: 100px;">
        </div></div></div>
        <span class="song-sides left-side"></span>
        <span class="song-sides right-side"></span>
        </div>
    </li>
</ul>

operating at the address http://www.efacil.com/#products.

However I would like that href below:

<a class="song-link" href="javascript:;" title=""></a>

Be adapted with this code below:

<a href="prod_index_marca.php?codmarca=<?php echo $res['codigo'];?>"><?php echo $res['nome_marca'];?></a>

so that when the user searched for the brand bring all products related to the selected brand, according to the address http://buziosnegocios.com.br/prod_index.php.

I don’t know if I could express myself in a way that friends can help me.

But I’m willing to answer any questions.

Hugs to all, and from now on my thanks for the attention to my doubt.

  • You need help creating that query string php or reading in Javascript?

  • I didn’t understand which event. Will the links appear on the page as a result of a search? Vc will use AJAX or will load a new page?

  • Come on, if you go to this address http://buziosnegocios.com.br/prod_index.php, you will see that when the user selects a certain brand, he returns to it all the products related to that brand selected in another page according to Cod. of the selected brand, OK? But what I intend to do and I have no idea how, is to create a link type the of this address, http://www.efacil.com/#products where the user clicks on Title 01 or 02, and returns to it the result on the same page, mounting a href with the two codes of href mentioned in the post. I ask my friends, is there any way?

1 answer

0


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.

Browser other questions tagged

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